Thymeleaf:有关于thyme leaf模板的介绍

在我们的日常开发中,总是要显示数据到页面,本人以前做的老项目的基本上都是Jsp,用Jsp的话,
后台和前端的交互代码繁琐,容易搞混,本人推荐thymeleaf模板进行前后端的分离,显示数据到页面

下面为大家写一个案例,让大家更好的认识thymeleaf,希望对初学者有所帮助。
1.首先我们看看application-dev.properties的配置

thymeleaf的模板配置
 
# thymeleaf模板配置 spring.thymeleaf.prefix= classpath:/templates/ spring.thymeleaf.suffix= .html spring.thymeleaf.mode= HTML5 spring.thymeleaf.encoding= UTF-8 spring.thymeleaf.cache= false spring.resources.chain.strategy.content.enabled= true spring.resources.chain.strategy.content.paths= /**
配置数据的thyme leaf模板,后缀名,html5的格式,字符编码格式
2.我写一个thymeleaf的controller案例给大家看看
//获取school的值
@RequestMapping("/school")
public  ModelAndView school(){
    ModelAndView mv=new ModelAndView();
    mv.addObject("school",schoolService.findAll());
    mv.setViewName("/school");
    return mv;
}
以这个显示school里面的数据为一个案例
3.我们看看这个school.html的显示数据的html5的代码
 
<!DOCTYPE HTML> < html xmlns= "http://www.w3.org/1999/xhtml" xmlns: th = "http://www.thymeleaf.org"> < head> < title>Hello,thymeleaf!</ title> < meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8"/> </ head> < body> < p th :text= " ${school}"></ p>< br/> </ body> </ html>
在这里我就简单的让大家更明白一点

4.输入路径进行访问页面,展示数据到页面
成功了,thymeleaf模板就是这么简单

关注本人微博:李日兴LRX

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码海兴辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值