MENU

更新一个老项目,Thymeleaf报错解决

March 15, 2020 • Jakarta


今天重新Build了一个老项目,项目是mvc架构的,更新了SpringBoot版本之后,运行项目报错,是关于thymeleaf的报错,如下:


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.

之后查了资料,发现需要更新变量的取出方式

修改前:

<button th:onclick="'loadUrl(\'/index/imei/delete?imei='+${imei.imei}+'\')'" title="删除"  
        class="layui-btn layui-btn-sm">
    <i class="layui-icon">&#xe640;</i>
</button>

修改后:

<button th:onclick="loadUrl('/index/imei/delete?imei='+[[${imei.imei}]])" title="删除"
        class="layui-btn layui-btn-sm">
    <i class="layui-icon">&#xe640;</i>
</button>
Archives QR Code
QR Code for this page
Tipping QR Code