Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
d3f6036c
Commit
d3f6036c
authored
Jun 19, 2019
by
qiuweili123
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify muli lang
parent
4d25c4c4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
25 deletions
+34
-25
ControllerResponseAdvice.java
web-starter/src/main/java/com/secoo/mall/web/advice/ControllerResponseAdvice.java
+5
-2
WebConfig.java
web-starter/src/main/java/com/secoo/mall/web/config/WebConfig.java
+4
-23
DefaultLocaleResolver.java
web-starter/src/main/java/com/secoo/mall/web/resolver/DefaultLocaleResolver.java
+25
-0
No files found.
web-starter/src/main/java/com/secoo/mall/web/advice/ControllerResponseAdvice.java
View file @
d3f6036c
...
@@ -8,6 +8,7 @@ import com.secoo.mall.common.util.response.ResponseUtil;
...
@@ -8,6 +8,7 @@ import com.secoo.mall.common.util.response.ResponseUtil;
import
com.secoo.mall.web.annotation.ApiController
;
import
com.secoo.mall.web.annotation.ApiController
;
import
com.secoo.mall.web.annotation.ApiIgnoreJson
;
import
com.secoo.mall.web.annotation.ApiIgnoreJson
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContext
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.core.annotation.AnnotationUtils
;
...
@@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
...
@@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.Locale
;
@RestControllerAdvice
(
annotations
=
ApiController
.
class
)
@RestControllerAdvice
(
annotations
=
ApiController
.
class
)
public
class
ControllerResponseAdvice
implements
ResponseBodyAdvice
<
Object
>
{
public
class
ControllerResponseAdvice
implements
ResponseBodyAdvice
<
Object
>
{
...
@@ -34,8 +36,9 @@ public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
...
@@ -34,8 +36,9 @@ public class ControllerResponseAdvice implements ResponseBodyAdvice<Object> {
@ExceptionHandler
(
ParameterException
.
class
)
@ExceptionHandler
(
ParameterException
.
class
)
public
Object
parameterExceptionHandler
(
ParameterException
e
)
{
public
Object
parameterExceptionHandler
(
ParameterException
e
)
{
LoggerUtil
.
info
(
getMsg
(
e
));
String
msg
=
getMsg
(
e
);
return
ResponseUtil
.
getFailResponse
(
e
.
getCode
(),
getMsg
(
e
));
LoggerUtil
.
info
(
msg
);
return
ResponseUtil
.
getFailResponse
(
e
.
getCode
(),
msg
);
}
}
@ExceptionHandler
(
Exception
.
class
)
@ExceptionHandler
(
Exception
.
class
)
...
...
web-starter/src/main/java/com/secoo/mall/web/config/WebConfig.java
View file @
d3f6036c
package
com
.
secoo
.
mall
.
web
.
config
;
package
com
.
secoo
.
mall
.
web
.
config
;
import
com.secoo.mall.web.resolver.DefaultLocaleResolver
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.support.ResourceBundleMessageSource
;
import
org.springframework.context.support.ResourceBundleMessageSource
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
;
import
org.springframework.web.servlet.i18n.CookieLocaleResolver
;
import
org.springframework.web.servlet.i18n.LocaleChangeInterceptor
;
import
org.springframework.web.servlet.i18n.LocaleChangeInterceptor
;
import
java.util.Locale
;
import
java.util.Locale
;
@Configuration
@Configuration
public
class
WebConfig
implements
WebMvcConfigurer
{
public
class
WebConfig
implements
WebMvcConfigurer
{
/**
* 自定义国际化文件存放路径
*
* @return
*/
/*@Bean
public org.springframework.validation.Validator getValidator() {
Validator validator = Validation.byDefaultProvider()
.configure()
.messageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator("i18n/message")))
.buildValidatorFactory().getValidator();
return (org.springframework.validation.Validator) validator;
}*/
@Bean
@Bean
public
ResourceBundleMessageSource
messageSource
()
{
public
ResourceBundleMessageSource
messageSource
()
{
ResourceBundleMessageSource
messageSource
=
new
ResourceBundleMessageSource
();
ResourceBundleMessageSource
messageSource
=
new
ResourceBundleMessageSource
();
...
@@ -34,16 +21,10 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -34,16 +21,10 @@ public class WebConfig implements WebMvcConfigurer {
return
messageSource
;
return
messageSource
;
}
}
@Bean
public
LocaleResolver
localeHeaderResolver
()
{
AcceptHeaderLocaleResolver
localeResolver
=
new
AcceptHeaderLocaleResolver
();
localeResolver
.
setDefaultLocale
(
Locale
.
SIMPLIFIED_CHINESE
);
return
localeResolver
;
}
@Bean
@Bean
(
name
=
"localeResolver"
)
public
LocaleResolver
localeCookieResolver
()
{
public
LocaleResolver
localeCookieResolver
()
{
CookieLocaleResolver
localeResolver
=
new
Cookie
LocaleResolver
();
DefaultLocaleResolver
localeResolver
=
new
Default
LocaleResolver
();
localeResolver
.
setCookieName
(
"language"
);
localeResolver
.
setCookieName
(
"language"
);
//设置默认区域
//设置默认区域
localeResolver
.
setDefaultLocale
(
Locale
.
SIMPLIFIED_CHINESE
);
localeResolver
.
setDefaultLocale
(
Locale
.
SIMPLIFIED_CHINESE
);
...
...
web-starter/src/main/java/com/secoo/mall/web/resolver/DefaultLocaleResolver.java
0 → 100644
View file @
d3f6036c
package
com
.
secoo
.
mall
.
web
.
resolver
;
import
com.secoo.mall.common.util.string.StringUtil
;
import
org.springframework.lang.Nullable
;
import
org.springframework.web.servlet.i18n.CookieLocaleResolver
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Locale
;
public
class
DefaultLocaleResolver
extends
CookieLocaleResolver
{
@Nullable
protected
Locale
determineDefaultLocale
(
HttpServletRequest
request
)
{
if
(!
StringUtil
.
isEmpty
(
request
.
getHeader
(
"Accept-Language"
)))
{
return
Locale
.
forLanguageTag
(
request
.
getHeader
(
"Accept-Language"
));
}
String
lang
=
request
.
getParameter
(
"lang"
);
if
(
StringUtil
.
isNotEmpty
(
lang
))
{
return
parseLocaleValue
(
lang
);
}
return
super
.
determineDefaultLocale
(
request
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment