SpringBoot的国际化

1.## 关于SpringBoot页面国际化的操作:
(1)、编写国际化配置文件;
PS:en_US代表英语、zh_CN代表中文形式
在这里插入图片描述
在语言文件中配置各个语言:
在这里插入图片描述

2.、使用ResourceBundleMessageSource管理国际化资源文件
2.1 在SpringBoot中已经自动配置好了管理国际化资源文件的组件;
在这里插入图片描述

3)、在页面使用fmt:message取出国际化内容 :
PS:注意要修改代码格式(改成UTF-8),不然就会出现乱码
在这里插入图片描述
在页面文件中利用Thymeleaf表达式在页面显示对应的语言:

th:text="#{login.tip}"    th:placeholder="#{login.username}"  th:text="#{login.password}"
[[#{login.remember}]]      都是thymeleaf表达式
<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.sign}">Sign in</button>
			<p class="mt-5 mb-3 text-muted">© 2017-2018</p>
			<a class="btn btn-sm" th:href="@{/login(l='zh_CN')}">中文</a>
			<a class="btn btn-sm" th:href="@{/login(l='en_US')}">English</a>
		</form>

	</body>

效果:根据浏览器语言设置的信息切换了国际化

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值