我是春季世界的新手,所以我编写了一个HelloWorld示例,编写了以下简单控制器:
Controller
@RequestMapping("/welcome")
public class HelloWorldController{
@RequestMapping(method = RequestMethod.GET)
public ModelAndView helloWorld(){
ModelAndView model = new ModelAndView("MVC_First_Page");
model.addObject("msg", "hello world");
return model;
}

我得到了以下错误:
Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers
Caused by: org.thymeleaf.exceptions.TemplateInputException: 解析模板“错误”时,模板可能不存在,或者任何已配置的模板解析器都无法访问模板。
为什么拦截器看不到MVC_First_Page.jsp页面?我已经将它的扩展更改为.html,并且它可以工作。
我应该将这个属性添加到application.properties文件中吗?
spring.mvc.view.prefix:
spring.mvc.view.suffix: .jsp发布于 2018-04-27 14:37:41
如果您不需要Thymeleaf (因为您只是在实验),最简单的方法就是只使用jsp视图解析器。
您可以在这里找到一个很好的例子:https://hellokoding.com/spring-boot-hello-world-example-with-jsp/
基本上,在代码中,您需要从pom.xml中删除Thymeleaf并添加jasper依赖项:
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-thymeleaf</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>然后,必须在application.properties文件中指定视图后缀:
spring.mvc.view.suffix=.jsp最后,您需要将JSP文件移动到src/main/webapp目录中。
https://stackoverflow.com/questions/50060670
复制相似问题