thymeleaf th:onclick报错 Only variable expressions returning numbers or booleans are allowed

错误:

使用th:onclick传字符参数的时候,报如下错误:

Caused by: org.attoparser.ParseException: 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.

解决办法:

通过thymeleaf的一种获取值的方法:[[${xx.name}]],可以直接获取xx里面的name值.

原代码:

<a href="#" th:οnclick="'javascript:item(\''+${skuLsInfo.id}+'\')'">

修改后的代码:

<a href="#" th:οnclick="item([[${skuLsInfo.id}]])">
 
发布了157 篇原创文章 · 获赞 1 · 访问量 2675

猜你喜欢

转载自blog.csdn.net/qq_34449717/article/details/105161596