springboot推荐使用thymeleaf模板引擎对html进行数据写入
引入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
版本更改(可能会版本冲突,最好不改版本)
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.0</thymeleaf-layout-dialect.version>
默认规则(ThymeleafProperties类),html放在classpath:/templates/下thymeleaf将会自动渲染

一、使用:
1:导入thymeleaf的名称空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
2:后端
@RequestMapping("demo1")
public String sayHi(Map<String,Object> map){
logger.info("访问成功");
map.put("name","张三");
return "demo1";
}
3:前端
<b th:text="${name}"></b>访问成功!
二、语法
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...





