pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
resources下的 application.properties文件
#thymeleaf 配置
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
#缓存设置为false, 这样修改之后马上生效,便于调试
spring.thymeleaf.cache=false
#上下文--
#不仅仅是一个路劲的前缀,而且是项目的名字groupId
server.servlet.context-path=/
resources下的templates目录下的hello.html文件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<!-- 你的HTML代码 -->
你好,爱上我了
</script>
</body>
</html>
controller中的类,当访问hello路径时会跳转到login的html页面
http://www.localhost:8080/hello
@Controller
public class ConTest {
@RequestMapping("/hello")
public String hello(Model model){
return "login";
}
}
但是要注意一下这种情况
controller中的只能使用@Controller的注解,不能使用@RestController。
关于@RestController,@Controller,@ResponseBody以及thymeleaf页面的搭配使用,最近我再另外一篇文章进行了使用场景进行了分析。附上链接
https://blog.csdn.net/qq_36838406/article/details/100867004