关于thymleaf中的各种标签的使用

将时间转成你想要的格式
<input type="date" th:value="${#dates.format(task.taskBegintime, 'yyyy-MM-dd')}" name="taskBegintime" id="taskBegintime">

单选框的回显
<label class="col-sm-3 control-label">紧急程度:</label>
  <div class="col-sm-8">
普通:<input type="radio" th:attr ="checked=${task.taskLevel == '普通'?true:false}" name="taskLevel" value="普通">
紧急: <input type="radio" th:attr ="checked=${task.taskLevel == '紧急'?true:false}" name="taskLevel" value="紧急">
非常紧急: <input type="radio" th:attr ="checked=${task.taskLevel == '非常紧急'?true:false}" name="taskLevel" value="非常紧急">
</div>

thymeleaf中th:attr多属性

使用thymeleafa时候如果要hidden某些数据,我们可以使用th:attr 将数据作为html标签的一个属性存起来

例如:       

1 <div id="cityBtn" class="btn" th:attr="data-cityId=${cityId}" th:text="${cityName}">上海
2    <span class="fa fa-angle-down"></span>
3 </div>

其中的 cityId是我们要保存起来的数据,然后就可以在js里面使用了。

使用方式为: 

1  var cityId = $("#cityBtn").data("cityid");

 如果是有多个属性要hidden,只需要用逗号隔开就可以了:

1 <div id="cityBtn" class="btn" th:attr="data-cityId=${cityId}, data-regionId=${regionId}" th:text="${cityName}"" >上海
2    <span class="fa fa-angle-down"></span>
3 </div>
 
原文地址:https://www.cnblogs.com/lndbky/p/13695391.html