解决Error resolving template template might not exist or might not be accessible问题

待我称王封你为后i 2022-05-25 11:20 291阅读 0赞

欢迎转载:攻城狮不是猫

thymeleaf + Spring Boot 在开发环境正常,但用jar运行时报错 Error resolving template template might not exist or might not be accessible;

这个问题我们都很好明白,就是模板页不存在,但是实际上它能找到模板页,但是在使用th:include标签的时候才会出错,这就是问题的症结所在。

其实这个问题也很好解决,我们只需要在引用模板文件的时候不用”/”打头就可以了,通过类似相对路径的方式来引用,但是需要说明的是,这里的相对路径仍然是相对于模板根目录来做的。

  1. @RequestMapping("/view")
  2. public String view() {
  3. return "/view";
  4. }

改成

  1. @RequestMapping("/view")
  2. public String view() {
  3. return "view";
  4. }

就可以了

20190612135905234.png

发表评论

表情:
评论列表 (有 0 条评论,291人围观)

还没有评论,来说两句吧...

相关阅读