thymeleaf -常见用法

pom.xml

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

可配参数

thymeleaf 模板配置


## 关闭thymeleaf缓存 开发时使用 否则没有实时画面
spring.thymeleaf.cache=false
spring.thymeleaf.check-template-location=true
spring.thymeleaf.enabled=true
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

常见用法

空值处理
取值如:file?name 不会报错

thymeleaf的循环 //循环,取值使用 file.???

<tr th:each="file:${files}"><tr>      

事件传单值------ user_update为方法名

 <button th:onclick="|user_update('${u.userId}')|" > </button> 

事件传多值

 <button th:onclick="|playfile(filepath='${file.pathfile}',name='${file.name}')|" > </button>

a连接传单值

<a th:href="@{/user/deleteId(id=${u.userId})}"</a>    

a连接传多值

<a th:href="@{/file/deleteId(id=${file.fileId},pathfile=${file.pathfile})}"></a>  

小数保留2位

<td th:text="${#numbers.formatDecimal(file.size,0,2)}">KB</td>     

时间类型

  <td th:text="${#dates.format(file.time,'yyyy-MM-dd HH:mm:ss')}"></td>  

自动赋值被勾选状态------- role.isExe = ‘yes’ 的

<input type="checkbox" th:value="${role.roleId}"  th:checked="${role.isExe eq 'yes' }"> 

select 后台取值回显数据

<select name="dep.depId">
    <option  th:each="dep:${deps}"  th:value="${dep.depId}" th:text="${dep.name}" value="1"></option>
</select>

select 联表复杂数据回显数据

<select  class="orderType" style="width: 190px;height:38px" >
    <option  th:selected="${dateil.orderGoods.orderType.orderTypeId eq type.orderTypeId}"      th:each="type:${dateil.orderGoods.orderType.orderFirm.orderTypeList}"     th:value="${type.orderTypeId}" th:text="${type.name}" value="1"></option>
</select>

select 选中状态

 <option th:value="1" th:selected="(${server.rechargeState}==1)">正常充值</option>
 <option th:value="2" th:selected="(${server.rechargeState}==2)">关闭充值</option>
 <option th:value="3" th:selected="(${server.rechargeState}==3)">直接发货</option>

多判断 可 ||

 th:if="${order.type == '运输单' && state != null && state != '' 

传字符串 (使用上面的方式传字符串错误,修正为项目格式,就是–> [[ 参数 ]]

     th:onclick="datajs([[${statisData?.data}]])"

静态资源添加时间戳(防缓存)

<link rel="stylesheet" th:href="@{../layuiadmin/layui/css/layui.css(time=${new java.util.Date().getTime()})}" 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值