简直愚蠢的错误:搞了我快一个小时,记录以自勉。
- 刚开始是出现了:Could not resolve view with name ‘index’ in servlet with name ‘dispatcherServlet’
有文章说是因为没有配置好静态资源的路径,但是我在application.properties中已经配置了html对应的路径:
#thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
#thymeleaf end
但是我还是尝试了网上所说的方式:启动类继承自WebConfigurationSurport,加上@EnableWebMvc注解:
详见:https://blog.youkuaiyun.com/testcs_dn/article/details/80249894
/**
* 配置JSP视图解析器
* 如果没有配置视图解析器。Spring会使用BeanNameViewResolver,通过查找ID与逻辑视图名称匹配且实现了View接口的beans
*
* @return
*/
@Bean
public InternalResourceViewResolver setupViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
/** 设置视图路径的前缀 */
resolver.setPrefix("/WEB-INF/jsp/");
/** 设置视图路径的后缀 */
resolver.setSuffix(".jsp");
return resolver;
}
-
然后出现了springmvc的Circular view path的错误:
javax.servlet.ServletException: Circular view path [login]: would dispatch back to the cu
有解决方案说是:@RequestMapping中的路径和html(或者jsp)文件名不要写成一样的,修改后还是无法解决问题。
还有说在Test类中重新配置一遍视图:https://blog.youkuaiyun.com/wthfeng/article/details/52742830
还有SpringMVC出现该问题的解决方案:https://blog.youkuaiyun.com/cjj1030833228/article/details/50993009
最后,你们知道是什么问题吗???是因为我没有在Pom中引入Thymeleaf的依赖!!简直愚蠢哈哈哈哈哈。
还有注意@RestController和@Controller的区别。