thymleaf知识点总结

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>
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值