6.thymeleaf入门

spring boot不支持使用动态资源,JSP不支持,推荐使用模板引擎,可以和jsp等价
一、引入模板引擎thymeleaf
网页= 模板+数据
spring.io网站里把spring-boot-starter-thymeleaf 依赖,把pom添加到配置文件里
引入thymeleaf : 1.到官网查询thymeleaf 依赖。2.在创建项目的时候添加

二、使用thymeleaf
ThymeleafAutoConfiguration(自动装配)
XXProperties(属性)
在spring-boot-autoconfiguration-xxxx.jar包里面找
1、代码在哪里写?
默认的前缀.html
默认后缀:classpath:/templates/
在src/main/resources/templates/下创建一个result.html
去官网 https://www.thymeleaf.org/ 看Docs查询如何使用
操作:


result.html代码如下:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p th:text="${welcome}">welcome</p>
</html>
修改BootController类添加一个welcome()方法
@RequestMapping("/welcome")
public String welcome(Map<String,Object> map){
//给thymeleaf准备数据
map.put("welcome","zs"); //spring mvc的知识
return "result";
}
用法类型EL表达式


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容