Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
453c3929
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
453c3929
编写于
6月 26, 2017
作者:
S
shenhongxi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
i18n
上级
4bf9bd11
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
31 addition
and
0 deletion
+31
-0
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/UserController.java
...java/com/itlong/whatsmars/spring/boot/UserController.java
+23
-0
whatsmars-spring-boot/src/main/resources/application-test.properties
...pring-boot/src/main/resources/application-test.properties
+3
-0
whatsmars-spring-boot/src/main/resources/i18n/messages.properties
...s-spring-boot/src/main/resources/i18n/messages.properties
+1
-0
whatsmars-spring-boot/src/main/resources/i18n/messages_en_US.properties
...ng-boot/src/main/resources/i18n/messages_en_US.properties
+1
-0
whatsmars-spring-boot/src/main/resources/i18n/messages_zh_CN.properties
...ng-boot/src/main/resources/i18n/messages_zh_CN.properties
+1
-0
whatsmars-spring-boot/src/main/resources/templates/index.html
...smars-spring-boot/src/main/resources/templates/index.html
+2
-0
未找到文件。
whatsmars-spring-boot/src/main/java/com/itlong/whatsmars/spring/boot/UserController.java
浏览文件 @
453c3929
package
com.itlong.whatsmars.spring.boot
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.i18n.FixedLocaleResolver
;
import
java.util.Locale
;
import
java.util.Map
;
/**
...
...
@@ -16,9 +22,26 @@ public class UserController {
@Autowired
private
UserConfig
userConfig
;
@Autowired
private
MessageSource
messageSource
;
/**
* 设置区域解析器 (default is AcceptHeaderLocaleResolver)
*/
@Bean
public
LocaleResolver
localeResolver
()
{
FixedLocaleResolver
slr
=
new
FixedLocaleResolver
();
slr
.
setDefaultLocale
(
Locale
.
US
);
return
slr
;
}
@RequestMapping
(
"/"
)
public
String
home
(
Map
<
String
,
Object
>
map
)
{
map
.
put
(
"hello"
,
"Hi, boy!"
);
Locale
locale
=
LocaleContextHolder
.
getLocale
();
String
country
=
messageSource
.
getMessage
(
"country"
,
null
,
locale
);
map
.
put
(
"country"
,
country
);
return
"index"
;
}
...
...
whatsmars-spring-boot/src/main/resources/application-test.properties
浏览文件 @
453c3929
...
...
@@ -60,3 +60,6 @@ user.welcome=Hello, World!
user.noFilterUrl
=
/,/login
spring.thymeleaf.cache
=
false
#i18n
spring.messages.basename
=
i18n/messages
whatsmars-spring-boot/src/main/resources/i18n/messages.properties
0 → 100644
浏览文件 @
453c3929
country
=
中国
\ No newline at end of file
whatsmars-spring-boot/src/main/resources/i18n/messages_en_US.properties
0 → 100644
浏览文件 @
453c3929
country
=
China
\ No newline at end of file
whatsmars-spring-boot/src/main/resources/i18n/messages_zh_CN.properties
0 → 100644
浏览文件 @
453c3929
country
=
\u
4e2d
\u
56fd
\ No newline at end of file
whatsmars-spring-boot/src/main/resources/templates/index.html
浏览文件 @
453c3929
...
...
@@ -7,5 +7,7 @@
<body>
<h1
th:inline=
"text"
>
thymeleaf
</h1>
<p
th:text=
"${hello}"
></p>
<p
th:text=
"${country}"
></p>
<p
th:text=
"#{country}"
></p>
</body>
</html>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录