thymeleaf的能用在什么地方_Thymeleaf的使用

SpringBoot集成Thymeleaf

使用Spring Initializr创建项目时勾选Thymeleaf,如果不使用Spring Initializr,需要手动添加Thymeleaf的依赖:

org.springframework.boot

spring-boot-starter-thymeleaf

Thymeleaf以html为原型,文件后缀是.html,使用Thymeleaf时创建html文件即可。

SpringBoot开箱即用,提供了大量的默认配置,一般使用默认配置即可。

SpringBoot的默认配置中,Thymeleaf的默认前缀是classpath:/resources/templates,默认后缀是.html。

开发、调试时关闭Thymeleaf的页面缓存:

#默认为true,使用页面缓存

spring.thymeleaf.cache=false

上线时改为true,或者删掉、注释掉。

Thymeleaf语法

1、th:text   显示普通文本

你好

=18 ? 已成年 : 未成年">

Thymeleaf所有的指令都以th:开头,th即Thymeleaf的前2个字母。

controller可以使用Model、ModelAndView来传递数据。

2、th:utext   具有th:text的功能,且可以解析标签

//controller传递的数据中带有html标签

model.addAttribute("msg", "

user

");

注意:是controller向html传递的数据中有html标签,不是直接在utext中写标签,如果是   

3、th:object  处理对象

比如说controller传了一个user对象,在html中要多处使用user对象,${user.xxx},每次都要写user,很麻烦,可以这样:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值