thymeleaf 如何在onclick传值 升级到springboot2.x时出错的解决方案

时间:2023-02-08 16:42:00

springboot2.x

按照下面那样传值会出现这样的错误

org.thymeleaf.exceptions.TemplateProcessingException: Only variable expressions returning numbers or booleans are allowed in this context, any other datatypes are not trusted in the context of this expression, including Strings or any other object that could be rendered as a text literal. A typical case is HTML attributes for event handlers (e.g. "onload"), in which textual data from variables should better be output to "data-*" attributes and then read from the event handler. (template: "dicAcl/list" - line 52, col 82)

解决方案

<button class="layui-btn layui-btn-sm layui-btn-normal"  th:data-thing = "${aclListVo.aclId}"  onclick = "update(this.getAttribute('data-thing'));">编辑</button>

 

springboot1.5.9

来个列子  

<button class="layui-btn layui-btn-sm layui-btn-normal" th:onclick="|update('${aclListVo.aclId}')|">编辑</button>


 thymeleaf 如何在onclick传值 升级到springboot2.x时出错的解决方案