thymeleaf中使用th:onclick出现的问题

在springboot2.x的环境中使用thymeleaf的onclick时,若安照如下方式使用onclick,就会报错TemplateProcessingException异常。

 
     
 

报错如下:

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: "rent-list" - line 82, col 36)

这个错误可以通过在${region.enName} 外面加上 [[${region.enName}]]解决,但是onclick事件却无法触发。

 
     
 

之后在网上查到了一种解决方法:


  

 

你可能感兴趣的:(SringBoot)