SpringBoot项目使用视图解析器解决Circular view path 问题

avatar 2018年01月01日23:32:48 6 30516 views
博主分享免费Java教学视频,B站账号:Java刘哥
在使用 SpringBoot 和 Thymeleaf 整合的时候,发现不管怎么样都是无法加载 Thymeaf 模板引擎。 比如 现在有控制器
  1. @Controller
  2. public class HelloController {
  3.     @GetMapping("/hello")
  4.     public String sayHello(Model model) {
  5.         model.addAttribute("name","琪琪");
  6.         //相当于访问 /templates/hello.html
  7.         return "hello";
  8.     }
  9. }
  resource/templates/hello.html
  1. <!DOCTYPE HTML>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3. <head>
  4.     <title>hello</title>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. </head>
  7. <body>
  8. <p th:text="'Hello!, ' + ${name} + '!'" ></p>
  9. </body>
  10. </html>
  最终报如题错误
javax.servlet.ServletException: Circular view path [hello]: would dispatch back to the current handler URL [/hello] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
 

问题原因

后来发现是自己的 thymleaf 的依赖包导错了。 之前导入的是(错误的)   正确导入    
  1. <dependency>
  2.     <groupId>org.springframework.boot</groupId>
  3.     <artifactId>spring-boot-starter-thymeleaf</artifactId>
  4. </dependency>
  本文链接: https://liuyanzhao.com/7099.html  
  • 微信
  • 交流学习,有偿服务
  • weinxin
  • 博客/Java交流群
  • 资源分享,问题解决,技术交流。群号:590480292
  • weinxin
avatar

发表评论

avatar 登录者:匿名
匿名评论,评论回复后会有邮件通知

  

已通过评论:1   待审核评论数:0
  1. avatar zxcxzczx

    测试