使用th:attr解决。
th:attr
to the rescue Thymeleaf documentation – Setting attribute values.
For your scenario, this should do the job:
<div th:attr="data-el_id=${element.getId()}">
XML rules do not allow you to set an attribute twice in a tag, so you can’t have more than one th:attr
in the same element.
Note: If you want more that one attribute, separate the different attributes by comma:如果想使用多个,方法如下
<div th:attr="data-id=${element.getId()},data-name=${element.getName()}">
如果想拼接字符串。
原地址:https://stackoverflow.com/questions/24411826/using-data-attribute-with-thymeleaf
- 本文固定链接: http://www.letg.top/?p=67
- 转载请注明: ubosm 于 点滴分享 发表
th:attr="data-id='some-text'+${element.getId()}+'some-other-text',data-name=${element.getName()}"