Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
member-api
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
曲欣亮
member-api
Commits
c8b51cec
Commit
c8b51cec
authored
Oct 15, 2018
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置语言环境到Cookie中
parent
10c993fb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
MemberOpenApiController.java
...main/java/com/egolm/film/api/MemberOpenApiController.java
+9
-2
LocaleSessionInterceptor.java
...olm/film/config/interceptor/LocaleSessionInterceptor.java
+2
-2
No files found.
src/main/java/com/egolm/film/api/MemberOpenApiController.java
View file @
c8b51cec
...
@@ -2,7 +2,9 @@ package com.egolm.film.api;
...
@@ -2,7 +2,9 @@ package com.egolm.film.api;
import
java.util.Locale
;
import
java.util.Locale
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -114,9 +116,14 @@ public class MemberOpenApiController {
...
@@ -114,9 +116,14 @@ public class MemberOpenApiController {
@PostMapping
(
"setLocale"
)
@PostMapping
(
"setLocale"
)
@ApiOperation
(
"设置语言环境"
)
@ApiOperation
(
"设置语言环境"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
dataType
=
"String"
,
required
=
true
,
name
=
"i18n_language"
,
defaultValue
=
"zh_CN"
)})
@ApiImplicitParams
({
@ApiImplicitParam
(
paramType
=
"query"
,
dataType
=
"String"
,
required
=
true
,
name
=
"i18n_language"
,
defaultValue
=
"zh_CN"
)})
public
Object
setLocale
(
HttpSession
session
,
String
i18n_language
)
{
public
Object
setLocale
(
HttpSession
session
,
HttpServletResponse
response
,
String
i18n_language
)
{
Locale
locale
=
new
Locale
(
i18n_language
);
Locale
locale
=
new
Locale
(
i18n_language
);
session
.
setAttribute
(
LocaleSessionInterceptor
.
I18N_LANGUAGE_SESSION
,
locale
);
session
.
setAttribute
(
LocaleSessionInterceptor
.
language
,
locale
);
Cookie
cookie
=
new
Cookie
(
LocaleSessionInterceptor
.
language
,
i18n_language
);
cookie
.
setHttpOnly
(
true
);
cookie
.
setMaxAge
(
3600
);
cookie
.
setPath
(
"/"
);
response
.
addCookie
(
cookie
);
return
Rjx
.
jsonOk
();
return
Rjx
.
jsonOk
();
}
}
...
...
src/main/java/com/egolm/film/config/interceptor/LocaleSessionInterceptor.java
View file @
c8b51cec
...
@@ -13,12 +13,12 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
...
@@ -13,12 +13,12 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@Component
@Component
public
class
LocaleSessionInterceptor
extends
HandlerInterceptorAdapter
{
public
class
LocaleSessionInterceptor
extends
HandlerInterceptorAdapter
{
public
static
final
String
I18N_LANGUAGE_SESSION
=
"I18N_LANGUAGE_SESSION
"
;
public
static
final
String
language
=
"i18n_language
"
;
@Override
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
HttpSession
session
=
req
.
getSession
();
HttpSession
session
=
req
.
getSession
();
Locale
locale
=
(
Locale
)
session
.
getAttribute
(
I18N_LANGUAGE_SESSION
);
Locale
locale
=
(
Locale
)
session
.
getAttribute
(
language
);
if
(
locale
==
null
)
{
if
(
locale
==
null
)
{
locale
=
req
.
getLocale
();
locale
=
req
.
getLocale
();
}
}
...
...
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