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代码如下:







welcome



修改BootController类添加一个welcome()方法
@RequestMapping("/welcome")
public String welcome(Map map){
//给thymeleaf准备数据
map.put("welcome","zs"); //spring mvc的知识
return "result";
}
用法类型EL表达式


你可能感兴趣的:(6.thymeleaf入门)