一、在resources下面添加templates文件夹并在下面建立index.html页面
123456789
Hello Word!!!
二、导入pom依赖 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
三、在application.properties中配置模板引擎
spring.thymeleaf.prefix=classpath:/templates/
四、创建controller
(这里有人说路径名 @GetMapping("/index")和返回名(return “index”))不能一样,我的项目中可以一样完全没有问题。
【本地启动浏览器输入localhost:端口号/index】
@Controller
public class DemoController {
@GetMapping("/index")
public String index(){
return "index";
}
}
如果返回的页面是字母index 那就是你的@Controller写成@RestController或者多加了@@ResponseBody
引用博主 https://blog.csdn.net/rocling/article/details/81676928