在使用LayUI和thymeleaf的时候发生的一个神奇的异常
有问题的代码
cols: [[
{checkbox: true, fixed: 'left', align: 'center'}
, {title: '商品', align: 'center', minWidth: 260, templet: '#goodsTpl'}
, {
field: 'goodsPrice', title: '单价', align: 'center', minWidth: 160, templet: function (data) {
return data.goods.goodsPrice;
}
}
, {field: 'shoppingcarNum', title: '数量', align: 'center', width: 150}
, {field: 'goodsSubtotal', title: '小计', align: 'center', width: 120}
, {title: '操作', align: 'center', width: 100, templet: '#shopTpl'}
]]
出现的异常
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/usershop.html]")] with root cause
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression:
在写完这块地方的代码时,是没有出现这个异常的,但是后来在我没有动过这坨代码的情况下出现了,其实这个异常就是一个LayUI与thymeleaf的一个语法兼容问题导致的。可是为什么会莫名其妙出现这个问题呢?原因就是我有一个习惯就是写完一块代码的时候习惯性的ctrl+alt+L,整体排版一下,结果就导致没有问题的代码变成了
cols: [[
{checkbox: true, fixed: 'left', align: 'center'}
, {title: '商品', align: 'center', minWidth: 260, templet: '#goodsTpl'}
, {
field: 'goodsPrice', title: '单价', align: 'center', minWidth: 160, templet: function (data) {
return data.goods.goodsPrice;
}
}
, {field: 'shoppingcarNum', title: '数量', align: 'center', width: 150}
, {field: 'goodsSubtotal', title: '小计', align: 'center', width: 120}
, {title: '操作', align: 'center', width: 100, templet: '#shopTpl'}
你可能还没发现哪里出现了问题,问题出在了 cols: [[
这个地方,正确的写法是 cols: [ [
,[ 与 [ 之间的空格没有了,这就是整体排版后给我删除了的空格,导致LayUI与thymeleaf语法冲突,最终出现这个异常。