1.hymeleaf块标签(空标签)th:block,标签本身不显示。
如table 里面tr->td
<th:block th:switch="${sales.operateMark}">
<td th:case="0" th:text="初始"/>
<td th:case="1" th:text="新增"/>
<td th:case="2" th:text="更新"/>
<td th:case="3" th:text="删除"/>
</th:block>
2.thymeleaf判断list是否为空
不为空:
th:if="${not #lists.isEmpty(listData)}"
为空:
th:if="${#lists.isEmpty(listData)}"
3.一篇解决 thymeleaf 下拉选的选中问题
https://blog.csdn.net/qq_40925189/article/details/102818274?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
4.用thymeleaf用标签给页面select下拉框赋值
<div class="form-group">
<label>性别</label> <select class="form-control" id="sex">
<option value="1" th:selected="${sex=='1'}">男</option>
<option value="2" th:selected="${sex=='2'}">女</option>
</select>
</div>
5.thymeleaf-layout-dialect 有了这个布局框架,你可以专注于body体的内容,不在纠结与left header footer 公共js css
6.thymeleaf中th:attr多属性
使用thymeleafa时候如果要hidden某些数据,我们可以使用th:attr 将数据作为html标签的一个属性存起来
例如:
<div id="cityBtn" class="btn" th:attr="data-cityId=${cityId}" th:text="${cityName}">上海
<span class="fa fa-angle-down"></span>
</div>
其中的 cityId是我们要保存起来的数据,然后就可以在js里面使用了。
使用方式为:
var cityId = $("#cityBtn").data("cityid");
如果是有多个属性要hidden,只需要用逗号隔开就可以了:
<div id="cityBtn" class="btn" th:attr="data-cityId=${cityId}, data-regionId=${regionId}" th:text="${cityName}"" >上海
<span class="fa fa-angle-down"></span>
</div>