注册 X
我已阅读并同意  服务条款
首页 > IT技术笔记 > 查看笔记

springboot使用thymeleaf的onclick标签传参后台异常

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: "list" - line 49, col 41)


3.x版本的thymeleaf为了防止注入攻击,升级了安全机制。

解决

修改前:

<button th:onclick="'javascript:del(this,\''+${quartzInfo.id}+'\');'" type="button"></button>

修改后:

<button th:data-id="${quartzInfo.id}" onclick="del(this,this.getAttribute('data-id'))" type="button"></button>




 打赏        分享



评论