学无先后,达者为师

网站首页 编程语言 正文

Layui碰上Thymeleaf的解析问题

作者:大梦. 更新时间: 2022-01-10 编程语言
一个Layui碰上Thymeleaf导致的一个问题

今天要做一个表格导出功能项目前端是Layui就想到它有一个组件是可以直接导出成Excel的二话不说整合完成(整合的方法网上很多)

测试例子:

LAY_EXCEL.exportExcel([['Hello', 'World', '!']], 'hello.xlsx', 'xlsx');

然后报错。

前端报的错:

image

后端报的错:

image

2021-10-13 15:58:20.328 [TemplateEngine.java:1136] - [THYMELEAF][http-nio-9001-exec-1] Exception processing template "marketing/newSMStimetask/task_list_newsms": An error happened during template parsing (template: "class path resource [templates/marketing/newSMStimetask/task_list_newsms.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/marketing/newSMStimetask/task_list_newsms.html]")
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
	at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
	at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) ~[thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
	at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) [thymeleaf-3.0.9.RELEASE.jar:3.0.9.RELEASE]
	at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:354) [thymeleaf-spring5-3.0.9.RELEASE.jar:3.0.9.RELEASE]

找了好久最后发现thymeleaf 将代码中的二维数组,两个中括号连着当成自己的标签去解析了。

解决方法:

​ 将两个连着的中括号中间加一个空格就行了

#修改前:

LAY_EXCEL.exportExcel([['Hello', 'World', '!']], 'hello.xlsx', 'xlsx');

#修改后:

LAY_EXCEL.exportExcel([ ['Hello', 'World', '!'] ], 'hello.xlsx', 'xlsx');

完美解决。

刚好今天LayUI官网下线了,特此记录一下。

原文链接:https://blog.csdn.net/qq_22832075/article/details/120746241

栏目分类
最近更新