默认访问首页 || 国际化||设置全局字符编码的默认设置
生活随笔
收集整理的這篇文章主要介紹了
默认访问首页 || 国际化||设置全局字符编码的默认设置
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
默認(rèn)訪問首頁
國際化
在spring中是這樣配置的
1)、編寫國際化配置文件;
2)、使用ResourceBundleMessageSource管理國際化資源文件
3)、在頁面使用?fmt:message?取出國際化內(nèi)容
在SpringBoot中是這樣配置的
1)、編寫國際化配置文件,抽取頁面需要顯示的國際化消息
2)、SpringBoot自動配置好了管理國際化資源文件的組件;
設(shè)置全局字符編碼的默認(rèn)設(shè)置
login.html
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta name="description" content=""><meta name="author" content=""><title>Signin Template for Bootstrap</title><!-- Bootstrap core CSS --><link href="asserts/css/bootstrap.min.css" th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}" rel="stylesheet"><!-- Custom styles for this template --><link href="asserts/css/signin.css" th:href="@{/asserts/css/signin.css}" rel="stylesheet"></head><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></html>效果:根據(jù)瀏覽器語言設(shè)置的信息切換了國際化;
原理:
? 國際化Locale(區(qū)域信息對象);LocaleResolver(獲取區(qū)域信息對象);
總結(jié)
以上是生活随笔為你收集整理的默认访问首页 || 国际化||设置全局字符编码的默认设置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 扩展SpringMVC WebMvcC
- 下一篇: 开发期间模板引擎页面修改以后,要实时生效