生活随笔
收集整理的這篇文章主要介紹了
Spring boot国际化
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
國際化
根據(jù)瀏覽器,語言設(shè)置的信息
自動切換國際化支持
Spring MVC實現(xiàn)過程
1、編寫國際化配置文件
2、使用ResourceBundleMessageSource管理國際化資源文件
3、在頁面使用fmt:message取出國際化內(nèi)容
Spring boot實現(xiàn)過程
1、編寫國際化配置文件
抽取頁面需要顯示的國際化消息
Login,默認(rèn)配置
Login_en_US,英文配置
Login_zh_CN,中文配置
Resource Bundle
直接編輯,每個字段的值
2、自動配置
SpringBoot自動配置好了
管理國際化資源文件的組件
MessageSourceAutoConfiguration
自定義的配置文件
可以直接放在類路徑下叫messages.properties
這樣,可以不用做任何的配置,直接使用國際化功能
指定配置文件
messageSource
setBasenames
設(shè)置國際化資源文件的基礎(chǔ)名
基礎(chǔ)名,表示去掉語言國家代碼的
3、去頁面獲取國際化的值
#{ },獲取國際化信息
th:text,是標(biāo)簽體里面的內(nèi)容
Input是一個字節(jié)數(shù)的,沒有標(biāo)簽體
可以使用行內(nèi)寫法
<input
type=
"checkbox" value=
"remember-me"/>
[[#{login.remember}]]
<body class="text-center"><form class="form-signin" action="dashboard.html" th:action="@{/user/login}" method="post"><img class="mb-4" th:src="@{/asserts/img/bootstrap-solid.svg}" src="asserts/img/bootstrap-solid.svg" alt="" width="72" height="72"><h1 class="h3 mb-3 font-weight-normal" th:text="#{login.tip}">Please sign in
</h1><p style="color: red" th:text="${msg}" th:if="${not #strings.isEmpty(msg)}"></p><label class="sr-only" th:text="#{login.username}">Username
</label><input type="text" name="username" class="form-control" placeholder="Username" th:placeholder="#{login.username}" required="" autofocus=""><label class="sr-only" th:text="#{login.password}">Password
</label><input type="password" name="password" class="form-control" placeholder="Password" th:placeholder="#{login.password}" required=""><div class="checkbox mb-3"><label><input type="checkbox" value="remember-me"/> [[#{login.remember}]]
</label></div><button class="btn btn-lg btn-primary btn-block" type="submit" th:text="#{login.btn}">Sign in
</button><p class="mt-5 mb-3 text-muted">? 2017-2018
</p><a class="btn btn-sm" th:href="@{/index.html(l='zh_CN')}">中文
</a><a class="btn btn-sm" th:href="@{/index.html(l='en_US')}">English
</a></form>
</body>
總結(jié)
以上是生活随笔為你收集整理的Spring boot国际化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。