公司一直是前后端分离项目,今天写了一个小demo,springboot集成thymeleaf引擎模板怎么也跳转不了html页面,后来试了好多次,终于成功了!!
1.首先、添加jar包、
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.其次 配置application.yml
#thymeleaf
spring:
thymeleaf:
mode: HTML5
prefix: classpath:/templates/
# suffix: .html
encoding: utf-8
cache: false
content-type: text/html
指的注意的是
3.建立html页面
终于一定要在templates文件夹下新建html页面,我这里在resources下的templates文件夹下新建了一个Hello.html页面
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<p style="color:red">hello world</p>
</body>
</html>
4.写controller
5.启动访问
这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上!!! | |
---|---|
欢迎加入技术群聊
更多推荐
springboot集成thymeleaf引擎模板跳转不了html页面
发布评论