springboot中Thymeleaf使用

一、pom.xml配置

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-thymeleaf</artifactId>
   <version>2.0.1.RELEASE</version>
</dependency>

、编写Controller

三、建html文件在此文件夹下

使用格式如下

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>小莉莉</h1>
<h1 id="" class=""  th:text="${admin}">这里是编写XXX的信息</h1>
<hr/>
<span th:text="${book.name}"></span><br/>
<span th:text="${book.author.age}"></span>
<hr/>
<span th:text="${session.book.name}"></span><br/>
<!--默认是request的作用域是不需要添加的-->
<span th:text="${admin}"></span>
<hr/>
<span th:text="${authors[1].name}"></span>
<span th:text="${maps.get('kevin').name}"></span>
<hr/>
<h4>基本选择结构的使用</h4>
<span th:if="${book.author.age} >=20">你老了</span>
<span  th:unless="${book.author.age} >=20">你还是小鲜肉</span>
<h4>switch选择结构的使用</h4>
<div th:switch="${book.author.age}">
  <span th:case="1">超滤机</span>
  <span th:case="2">拖拉机</span>
    <span th:case="*">小母鸡</span>
</div>
<hr/>
<h4>循环的使用</h4>
<select >
<option  th:each="author, authorstart :${authors}" th:value="${authorstart.index}" th:text="${author.name}"></option>
</select>
<hr/>
<h4>单选按钮</h4>
<input   th:checked="${book.author.role==1}" type="radio" name="love">莉莉 <input th:checked="${book.author.role==2}" type="radio" name="love">姐姐
</body>
</html>

四、application中编写关闭缓存和格式要求简单化


spring.thymeleaf.cache=false
spring.thymeleaf.mode=LEGACYHTML5

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值