springboot thymeleaf 需要使用data-*,自定义属性,获取值怎么操作

springboot thymeleaf的页面中,设置属性,一般都是使用th:text,这样的确是可以设置比如a的属性或者p等等的属性,现在我循环遍历,显示多个菜单的时候,我需要增加一个自定义的属性,以便于点击的时候能够传递参数,所以想到html中的data-ceshi,类似于这样的自定义属性,thymeleaf还真提供了这种形式,参考国外的问答网址如下

https://stackoverflow.com/questions/24411826/using-data-attribute-with-thymeleaf:

具体操作如下,通过th:attr自定义data-*

<ul class="nav nav-second-level collapse">
<li th:each="cmenu : ${menu.children}">
<a class="menuItem" th:text="${cmenu.menuName}" th:href="@{${cmenu.url}}" th:attr="data-menuid=${cmenu.menuId},data-title=${menu.menuTitle}" >二级菜单</a>
</li>
</ul>

posted @ 2018-08-05 10:25  EchoXian  阅读(587)  评论(0编辑  收藏  举报