前台代码
<table id="uesrList" lay-filter="userTable" lay-data="{url:'/user/getUserList'}"></table> <script type="text/javascript" th:inline="none"> // $('.collapsed').collapse() $(function() { layui.use('table', function(){ var table = layui.table; table.render({ elem: '#test' ,url:'/user/getUserList' ,cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增 ,method: 'post' //默认:get请求 ,cols: [[ {field:'id', width:80, title: 'ID', sort: true} ,{field:'loginName', width:80, title: '登录名'} ,{field:'email', width:80, title: '邮箱', sort: true} ,{field:'phone', width:80, title: 'phone'} ,{field:'userType', title: '用户类型', sort: true} ,{field:'name', title: '姓名', sort: true} ,{field:'password', title: '密码'} ]] }); }); }); </script> |
异常:
是
报错的位置提示在 cols:[[…]],就是[[]]里面的内容不能渲染
2018-06-29 14:07:51.492 ERROR 8980 — [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : 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/user/userList.html]”)] with root cause org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: “ {field:’id’, width:80, title: ‘ID’, sort: true} ,{field:’loginName’, width:80, title: ‘登录名’} ,{field:’email’, width:80, title: ‘邮箱’, sort: true} ,{field:’phone’, width:80, title: ‘phone’} ,{field:’userType’, title: ‘用户类型’, sort: true} ,{field:’name’, title: ‘姓名’, sort: true} ,{field:’password’, title: ‘密码’} ” (template: “user/userList” - line 61, col 14) |
这个问题搞得我头大,因为第一次使用springboot,也不知道在干什么,后来在网上找到了答案
因为“[[]]”[[…]]之间的表达式在Thymeleaf被认为是内联表达式
解决方法:1、或者在script标签里 th:inline=”none” 就可以了
2、将[[]]换行成
[
[
]
]
即可
原文链接:https://blog.csdn.net/boke7265/article/details/80855958