Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
611e176a
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 搜索 >>
提交
611e176a
编写于
8月 16, 2020
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
whatsmars-boot-sample-thymeleaf
上级
24602e21
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
160 addition
and
0 deletion
+160
-0
whatsmars-spring-boot-samples/pom.xml
whatsmars-spring-boot-samples/pom.xml
+1
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/pom.xml
...ring-boot-samples/whatsmars-boot-sample-thymeleaf/pom.xml
+25
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/java/org/hongxi/whatsmars/boot/sample/thymeleaf/Application.java
...g/hongxi/whatsmars/boot/sample/thymeleaf/Application.java
+15
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/java/org/hongxi/whatsmars/boot/sample/thymeleaf/common/LocaleService.java
...whatsmars/boot/sample/thymeleaf/common/LocaleService.java
+35
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/java/org/hongxi/whatsmars/boot/sample/thymeleaf/controller/HomeController.java
...mars/boot/sample/thymeleaf/controller/HomeController.java
+58
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/application.yml
...-boot-sample-thymeleaf/src/main/resources/application.yml
+7
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/i18n/messages.properties
...ple-thymeleaf/src/main/resources/i18n/messages.properties
+1
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/i18n/messages_en_US.properties
...ymeleaf/src/main/resources/i18n/messages_en_US.properties
+1
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/i18n/messages_zh_CN.properties
...ymeleaf/src/main/resources/i18n/messages_zh_CN.properties
+1
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/static/red.jpg
...s-boot-sample-thymeleaf/src/main/resources/static/red.jpg
+0
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/templates/index.html
...-sample-thymeleaf/src/main/resources/templates/index.html
+13
-0
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/resources/application.yml
...tsmars-boot-sample-web/src/main/resources/application.yml
+3
-0
未找到文件。
whatsmars-spring-boot-samples/pom.xml
浏览文件 @
611e176a
...
...
@@ -28,6 +28,7 @@
<module>
whatsmars-boot-sample-web
</module>
<module>
whatsmars-boot-sample-async
</module>
<module>
whatsmars-boot-sample-datasource
</module>
<module>
whatsmars-boot-sample-thymeleaf
</module>
</modules>
<dependencies>
...
...
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/pom.xml
0 → 100644
浏览文件 @
611e176a
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-spring-boot-samples
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
Rocket.S8
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-boot-sample-thymeleaf
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/java/org/hongxi/whatsmars/boot/sample/thymeleaf/Application.java
0 → 100644
浏览文件 @
611e176a
package
org.hongxi.whatsmars.boot.sample.thymeleaf
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
/**
* Created by shenhongxi on 2020/8/16.
*/
@SpringBootApplication
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Application
.
class
,
args
);
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/java/org/hongxi/whatsmars/boot/sample/thymeleaf/common/LocaleService.java
0 → 100644
浏览文件 @
611e176a
package
org.hongxi.whatsmars.boot.sample.thymeleaf.common
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.MessageSource
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Component
;
import
java.util.Locale
;
/**
* Created by shenhongxi on 2017/6/28.
*/
@Component
public
class
LocaleService
{
public
static
final
Locale
DEFAULT_LOCALE
=
Locale
.
SIMPLIFIED_CHINESE
;
@Autowired
private
MessageSource
messageSource
;
public
String
getMessage
(
String
key
)
{
Locale
locale
=
LocaleContextHolder
.
getLocale
();
return
messageSource
.
getMessage
(
key
,
null
,
locale
);
}
public
static
boolean
isUSLocale
()
{
return
LocaleContextHolder
.
getLocale
().
equals
(
Locale
.
US
);
}
public
static
Locale
resetLocale
(
Locale
locale
)
{
Locale
origin
=
LocaleContextHolder
.
getLocale
();
LocaleContextHolder
.
setLocale
(
locale
);
return
origin
;
}
}
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/java/org/hongxi/whatsmars/boot/sample/thymeleaf/controller/HomeController.java
0 → 100644
浏览文件 @
611e176a
package
org.hongxi.whatsmars.boot.sample.thymeleaf.controller
;
import
org.hongxi.whatsmars.boot.sample.thymeleaf.common.LocaleService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.servlet.LocaleResolver
;
import
org.springframework.web.servlet.i18n.CookieLocaleResolver
;
import
org.springframework.web.servlet.support.RequestContextUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.Locale
;
import
java.util.Map
;
/**
* Created by shenhongxi on 2020/8/16.
*/
@Controller
public
class
HomeController
{
@Autowired
private
LocaleService
localeService
;
/**
* 设置区域解析器 (default is AcceptHeaderLocaleResolver)
*/
@Bean
public
LocaleResolver
localeResolver
()
{
CookieLocaleResolver
localeResolver
=
new
CookieLocaleResolver
();
localeResolver
.
setCookieName
(
"language"
);
localeResolver
.
setCookieMaxAge
(
Integer
.
MAX_VALUE
);
localeResolver
.
setDefaultLocale
(
LocaleService
.
DEFAULT_LOCALE
);
// Locale.getDefault()
return
localeResolver
;
}
@PostMapping
(
value
=
"/changeLang"
)
@ResponseBody
public
String
changeLang
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
String
lang
){
LocaleResolver
localeResolver
=
RequestContextUtils
.
getLocaleResolver
(
request
);
if
(
"zh"
.
equals
(
lang
))
{
localeResolver
.
setLocale
(
request
,
response
,
Locale
.
SIMPLIFIED_CHINESE
);
}
else
if
(
"en"
.
equals
(
lang
)){
localeResolver
.
setLocale
(
request
,
response
,
Locale
.
US
);
}
return
"lang:"
+
LocaleContextHolder
.
getLocale
().
getLanguage
();
}
@GetMapping
(
"/"
)
public
String
home
(
Map
<
String
,
Object
>
map
)
{
System
.
out
.
println
(
LocaleService
.
isUSLocale
());
map
.
put
(
"hello"
,
"Hi, boy!"
);
map
.
put
(
"country"
,
localeService
.
getMessage
(
"country"
));
return
"index"
;
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/application.yml
0 → 100644
浏览文件 @
611e176a
spring
:
profiles
:
active
:
dev
thymeleaf
:
cache
:
false
messages
:
basename
:
i18n/messages
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/i18n/messages.properties
0 → 100644
浏览文件 @
611e176a
country
=
中国
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/i18n/messages_en_US.properties
0 → 100644
浏览文件 @
611e176a
country
=
China
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/i18n/messages_zh_CN.properties
0 → 100644
浏览文件 @
611e176a
country
=
\u
4e2d
\u
56fd
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/static/red.jpg
0 → 100644
浏览文件 @
611e176a
10.5 KB
whatsmars-spring-boot-samples/whatsmars-boot-sample-thymeleaf/src/main/resources/templates/index.html
0 → 100644
浏览文件 @
611e176a
<!DOCTYPE html>
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
>
<head>
<title>
thymeleaf
</title>
</head>
<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
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/resources/application.yml
0 → 100644
浏览文件 @
611e176a
spring
:
jackson
:
date-format
:
yyyy-MM-dd HH:mm:ss
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录