项目场景:
controller实现跳转页面至index
- 项目结构
- 导入依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
- controller
@Controller
public class AlipayController {
@RequestMapping("/")
public String index(){
return "index";
}
}
问题描述:
无法跳转的指定页面,如下图。
原因分析:
idea代码提示:Cannot resolve MVC View ‘index‘
- 说明没找到我们的index.html页面,很多时候可能是我们的路径没写正确,但是我这里的路径没有问题。
- 注意:我的index.html并不是放在static文件夹中,而是templates文件夹中,该文件夹应存放的是thymeleaf模板页面。
解决方案:
- 导入依赖即可
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
- 另外若你的html页面需要使用thymeleaf的功能,需要添加命名空间
<html xmlns:th="http://www.thymeleaf.org">