省流:仔细看错误提示,不一定是后台代码报错,可能错误出现在模板页面
1、在使用thymeleaf做页面静态化时,报了TemplateInputException错误:
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/detail.html]")
2、一执行templateEngine.process()就报错,经过108000秒的艰难排错后,发现问题出现在自己的模板页面,除了上面这个TemplateInputException(视图解析异常),向下看还有parseexception(运行时异常),具体错误如下:
Caused by: org.attoparser.ParseException: Link base "/course/list" cannot be context relative (/...) unless the context used for executing the engine implements the org.thymeleaf.context.IWebContext interface (template: "detail" - line 364, col 12)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Link base "/course/list" cannot be context relative (/...) unless the context used for executing the engine implements the org.thymeleaf.context.IWebContext interface (template: "detail" - line 364, col 12)
3、经过报错提示,找到我的模板页面使用th:href="@{/course/list}"报了错,经过改正再次生成模板静态化页面,流畅运行。
4、经验总结:
1)一定要仔细看错误提示,本人因为没有仔细看报错提示,一直盯TemplateInputException(视图解析异常)找错误,白白浪费了几个小时。
2)在确定后台代码没问题的前提下,检查一下模板页面,很有可能是模板页面出现了问题。
3)这个问题不具有通用性。我的其他小伙伴也是下面的写法,就不会报错,具体原因,仍不清楚。
5、求教:
有没有大佬,可以解释一下,可能是什么地方导致了这个错误,为什么有人这么写的就不会报错呢?