美文网首页springboot
16.SpringBoot整合thymeleaf

16.SpringBoot整合thymeleaf

作者: 0f701952a44b | 来源:发表于2020-04-10 11:42 被阅读0次
1.Thymeleaf相关maven依赖
<!-- 使用Thymeleaf视图构建MVC Web应用程序的入门 (springboot推荐使用)-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2.Thymeleaf基础配置(application.properties)
#thymeleaf基础配置
#开发时关闭缓存,不然没法看到实时页面 
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
#前缀 
spring.thymeleaf.prefix=classpath:/templates/
#编码 
spring.thymeleaf.encoding=UTF-8
#类型 
spring.thymeleaf.servlet.content-type=text/html
#名称的后缀 
spring.thymeleaf.suffix=.html
3、建立文件夹

1)src/main/resources/templates/thymeleaf/
2)建立一个testthymeleaf.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <h1 th:text=${serverdata.serverclasspath}>测试内容1</h1>
    <h1 th:text=${serverdata.servername}>测试内容2</h1>
</body>
</html>

注:${serverdata.serverclasspath}、${serverdata.servername}获取后端controller返回数据

相关文章

网友评论

    本文标题:16.SpringBoot整合thymeleaf

    本文链接:https://www.haomeiwen.com/subject/aiwlmhtx.html