spring boot使用SpringMVC怎么才能返回一个视图,比如jsp

现在的情况是只能返回一个json.

报错信息如下:

javax.servlet.ServletException: Circular view path [/WEB-INF/jsp/welcome.jsp]: would dispatch back to the current handler URL [/WEB-INF/jsp/welcome.jsp] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

配置文件:
图片描述

图片描述

图片描述

阅读 19.8k
4 个回答

虽然没试过,我觉得jsp文件应该放在resources下面

据说spring boot支持最好的是thymeleaf,html里面直接写模板标签就好了,虽然我也是初学者,不过我看到很多教程建议不要用JSP,所以你的问题应该很少有人遇到^^

官方不建议JSP的,freemarker什么的都可以

一,我个人认为的问题出现原因:没有引入jsp的依赖包。
二,我个人推荐的解决方式:
1.在build.gradle文件中的dependencies{}里添加模板引擎的依赖,例如thymeleaf。
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
2.在application.properties文件里对刚才添加的依赖进行一些必要的配置。
例如:
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题