异常信息:
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/root/function.html]")
# ....
Caused by: org.attoparser.ParseException: Could not parse as expression: "#" (template: "commons/rootBar" - line 40, col 20)
异常表明:
#
不能作为一个表达式解析。
一开始,以为是在th:replace
替换时,#
id选择器引用错误,但在多次实验后,发现该处并没有错误。
<div th:replace="commons/rootBar :: #rootSidebar(uri='rootFunction')"></div>
最后发现,在使用th:href
时还没有写相应的controller,就暂时用#代替。而在thymeleaf中#
是有特殊含义的,不能随便使用,将#
换成对应url就可以了。
<a class="nav-link" href="#" th:href="#">
总结
- 抛异常时,一定要先看控制台中异常的行号,确认没有问题后,再考虑其他肯能会出问题的地方。
- thymeleaf解析异常,一般都是在使用相关表达式时错写或漏写的情况。