Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
sentinel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
曲欣亮
sentinel
Commits
5ecfe004
Commit
5ecfe004
authored
Nov 13, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改国际化设置
parent
33bf10ca
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
16 deletions
+13
-16
MemberOpenApiController.java
...va/com/egolm/film/api/member/MemberOpenApiController.java
+4
-7
WebMvcConfig.java
src/main/java/com/egolm/film/config/WebMvcConfig.java
+2
-2
LocaleCookieInterceptor.java
...golm/film/config/interceptor/LocaleCookieInterceptor.java
+7
-7
No files found.
src/main/java/com/egolm/film/api/member/MemberOpenApiController.java
View file @
5ecfe004
...
...
@@ -5,7 +5,6 @@ import java.util.Locale;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.i18n.LocaleContextHolder
;
...
...
@@ -23,7 +22,7 @@ import com.egolm.film.api.common.service.Messages;
import
com.egolm.film.api.member.service.MemberService
;
import
com.egolm.film.bean.Fc_member
;
import
com.egolm.film.config.XException
;
import
com.egolm.film.config.interceptor.Locale
Session
Interceptor
;
import
com.egolm.film.config.interceptor.Locale
Cookie
Interceptor
;
import
com.egolm.film.util.Common
;
import
io.swagger.annotations.Api
;
...
...
@@ -122,12 +121,10 @@ public class MemberOpenApiController {
@PostMapping
(
"setLocale"
)
@ApiOperation
(
"设置语言环境"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
dataType
=
"String"
,
required
=
true
,
name
=
"i18n_language"
,
defaultValue
=
"zh_CN"
)})
public
Object
setLocale
(
HttpSession
session
,
HttpServletResponse
response
,
String
i18n_language
)
{
Locale
locale
=
new
Locale
(
i18n_language
);
session
.
setAttribute
(
LocaleSessionInterceptor
.
language
,
locale
);
Cookie
cookie
=
new
Cookie
(
LocaleSessionInterceptor
.
language
,
i18n_language
);
public
Object
setLocale
(
HttpServletResponse
response
,
String
i18n_language
)
{
Cookie
cookie
=
new
Cookie
(
LocaleCookieInterceptor
.
language
,
i18n_language
);
cookie
.
setHttpOnly
(
true
);
cookie
.
setMaxAge
(
3600
);
cookie
.
setMaxAge
(
3600
000
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
return
Rjx
.
jsonOk
();
...
...
src/main/java/com/egolm/film/config/WebMvcConfig.java
View file @
5ecfe004
...
...
@@ -19,7 +19,7 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
com.egolm.film.config.interceptor.AdminLoginInterceptor
;
import
com.egolm.film.config.interceptor.Locale
Session
Interceptor
;
import
com.egolm.film.config.interceptor.Locale
Cookie
Interceptor
;
import
com.egolm.film.config.interceptor.MemberLoginInterceptor
;
import
com.egolm.film.config.interceptor.UserLoginInterceptor
;
...
...
@@ -36,7 +36,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
private
MemberLoginInterceptor
memberLoginInterceptor
;
@Autowired
private
Locale
Session
Interceptor
localeSessionInterceptor
;
private
Locale
Cookie
Interceptor
localeSessionInterceptor
;
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
...
...
src/main/java/com/egolm/film/config/interceptor/Locale
Session
Interceptor.java
→
src/main/java/com/egolm/film/config/interceptor/Locale
Cookie
Interceptor.java
View file @
5ecfe004
...
...
@@ -2,27 +2,27 @@ package com.egolm.film.config.interceptor;
import
java.util.Locale
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
@Component
public
class
Locale
Session
Interceptor
extends
HandlerInterceptorAdapter
{
public
class
Locale
Cookie
Interceptor
extends
HandlerInterceptorAdapter
{
public
static
final
String
language
=
"i18n_language"
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
HttpSession
session
=
req
.
getSession
();
Locale
locale
=
(
Locale
)
session
.
getAttribute
(
language
);
if
(
locale
==
null
)
{
locale
=
req
.
getLocale
();
Cookie
[]
cookies
=
req
.
getCookies
();
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
language
))
{
LocaleContextHolder
.
setLocale
(
new
Locale
(
cookie
.
getValue
()));
}
}
LocaleContextHolder
.
setLocale
(
locale
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
...
...
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