要修改的文件
1.在porm文件中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
2.java代码
@Controller
public class IndexController {
@RequestMapping("/vm")
public String news(){
return "hello";//hello是页面的名字,用hello.html也可以
}
}
3.在src/main/resources/templates中创建一个hello.html文件用于显示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<h3>hello themeleaf</h3>
</body>
</html>
4.(可选)如果按上面步骤还不行的话可以试试在application.properties文件中添加
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.cache=false