問題描述
th:class動態添加CSS class會覆蓋現有class屬性,導致class較多時,表達式過長。
官方文檔
https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#appending-and-prepending
解決方案
th:classappend:用於在不覆蓋現有屬性的情況下向元素添加CSS class。
<tr th:each="prod : ${prods}" class="row" th:classappend="${prodStat.odd}? 'odd'">
擴展
參考文章
https://blog.csdn.net/weixin_44357646/article/details/100837365