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

posted @   码海兴辰  阅读(78)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示