thymeleaf模板怎么在SpringBoot中使用

  介绍

今天就跟大家聊聊有关thymeleaf模板怎么在SpringBoot中使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

1。导入依赖

, & lt; !——,添加thymeleaf模版的依赖,——比;   ,,& lt; dependency>   ,,,,,& lt; groupId> org.springframework.boot,   ,,,,,& lt; artifactId> spring-boot-starter-thymeleaf,   & lt;才能/dependency>

2.应用程序。yml文件中新增thymeleaf配置

# # #配置thymeleaf   春天:   ,thymeleaf:   缓存:才能,假

3。创建实体类

public  class  Student  {   private 才能;Integer  stu_id;   private 才能;String  stu_name;      public 才能;Integer  getStu_id (), {   ,,,return  stu_id;   ,,}      public 才能;void  setStu_id (Integer  stu_id), {   ,,,this.stu_id =, stu_id;   ,,}      public 才能;学生(Integer  stu_id, String  stu_name), {   ,,,this.stu_id =, stu_id;   ,,,this.stu_name =, stu_name;   ,,}      public 才能;String  getStu_name (), {   ,,,return  stu_name;   ,,}      public 才能;void  setStu_name (String  stu_name), {   ,,,this.stu_name =, stu_name;   ,,}   }

4。在src/main/资源文件夹下创建模板文件夹

并创建一个索引。html以备后续使用

 thymeleaf模板怎么在SpringBoot中使用“> </p> <p> 5。创建一个ThyController类</p> <pre类= @ controller   @RequestMapping (“/thyController")   public  class  ThyController  {   @RequestMapping才能(“/thymeleaf")   public 才能;String  thymeleaf (Model 模型){   ,,,List,列表=new  ArrayList<在();   ,,,Student  stu1=new 学生(1,“张三“);   ,,,Student  stu2=new 学生(2,“李四“);   ,,,Student  stu3=new 学生(3,“王五“);      ,,,list.add (stu1);   ,,,list.add (stu2);   ,,,list.add (stu3);      ,,,model.addAttribute (“stuList"、列表);   ,,,return “index";   ,,}   }

6.你好。html页面

& lt; ! DOCTYPE  html>   & lt; html  lang=癳n", xmlns: th=癶ttp://www.w3.org/1999/xhtml"比;   & lt; head>   & lt;才能meta  charset=癠TF-8"/比;   & lt;才能title> ss</title>   & lt;/head>   & lt; body>   & lt; ul  th:每个=八雇?$ {stuList}“比;   & lt;才能li> & lt; span  th:文本=? {stu.stu_id}“祝辞& lt;/span> & lt; span  th:文本=? {stu.stu_name}“祝辞& lt;/span> & lt;/li>   & lt;/ul>   & lt;/body>   & lt;/html>

7。浏览器测试

 thymeleaf模板怎么在SpringBoot中使用“> </p> <p class=看完上述内容,你们对thymeleaf模板怎么在SpringBoot中使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

thymeleaf模板怎么在SpringBoot中使用