SpringBoot快速配置 2021-09-06

SpringBoot快速配置

			<properties>
			<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
			<!‐‐ 切换thymeleaf版本 布局功能的支持程序 thymeleaf3主程序 layout2以上版本 ‐‐>
			<!‐‐ thymeleaf2 layout1‐‐>
			<thymeleaf‐layout‐dialect.version>2.2.2</thymeleaf‐layout‐dialect.version>
			</properties>

			 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring‐boot‐starter‐thymeleaf</artifactId>
        </dependency>

导入thymeleaf的名称空间

<html lang="en" xmlns:th="http://www.thymeleaf.org">

thymeleaf的简单表达式
${…} 变量表达式 获取请求域、session域、对象等值
  *{…} 选择变量表达式 获取上下文对象值
  #{…} 消息表达式 获取国际化等值
  @{…} 链接url表达式
  片段表达式 ~{…} jsp:include 作用,引入公共页面片段

国际化设置

login.password=密码
login.remeber=记住我
login.signin=登录
login.tip=请登录
login.username=用户名

在html页面中将需要国际化的部分进行修改

th:text="#{login.username}"
<label class="sr-only"th:text="#{login.username}">Username</label>
th:text="#{login.password}"
<label class="sr-only"th:text="#{login.password}">Password</label>

对超链接进行赋值,添加国际化属性,

<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>

thymeleaf中可以使用小括号代替?进行分割效果为index.html?l=zh_CN
设置国际化程序:

/**
* 可以在连接上携带区域信息
*/
			public class MyLocaleResolver implements LocaleResolver {
			@Override
			public Locale resolveLocale(HttpServletRequest request) {
			String l = request.getParameter("l");
			Locale locale = Locale.getDefault();
			if(!StringUtils.isEmpty(l)){
			String[] split = l.split("_");
			locale = new Locale(split[0],split[1]);
			}
			return locale;
			}
			@Override
			public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale
			locale) {
			}
			}
			@Bean
			public LocaleResolver localeResolver(){
			return new MyLocaleResolver();
			}
			}

浪费了好几个小时
表单中跳转页面是th:action,不是th:href
引入bootstrap

<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
      integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

设置分页导航高亮可以通过三元运算符来实现:

th:class="${pages==page.getCurrent()}?'active':''" 

在li标签中添加class的三元运算

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值