最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot使用thymeleaf模板過程解析

 更新時間:2019年12月13日 10:09:19   作者:優(yōu)秀aaa  
這篇文章主要介紹了SpringBoot使用thymeleaf模板過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

這篇文章主要介紹了SpringBoot使用thymeleaf模板過程解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

1.導(dǎo)入依賴

 <!-- 添加thymeleaf模版的依賴 -->
   <dependency>
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-thymeleaf</artifactId> 
  </dependency>

2.application.yml文件中新增thymeleaf配置

###配置thymeleaf
spring:
 thymeleaf:
  cache: false

3.創(chuàng)建實體類

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 Student(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/resource文件夾下創(chuàng)建templates文件夾

并創(chuàng)建一個index.html以備后續(xù)使用

5.創(chuàng)建一個ThyController類

@Controller
@RequestMapping("/thyController")
public class ThyController {
  @RequestMapping("/thymeleaf")
  public String thymeleaf(Model model){
    List<Student> list=new ArrayList<>();
    Student stu1=new Student(1,"張三");
    Student stu2=new Student(2,"李四");
    Student stu3=new Student(3,"王五");

    list.add(stu1);
    list.add(stu2);
    list.add(stu3);

    model.addAttribute("stuList",list);
    return "index";
  }
}

6.hello.html頁面

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="UTF-8"/>
  <title>ss</title>
</head>
<body>
<ul th:each="stu:${stuList}">
  <li><span th:text="${stu.stu_id}"></span><span th:text="${stu.stu_name}"></span></li>
</ul>
</body>
</html>

7. 瀏覽器測試

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

高碑店市| 资中县| 佛冈县| 新营市| 婺源县| 吴桥县| 宝兴县| 岑巩县| 广平县| 津南区| 庄河市| 邯郸县| 乌拉特后旗| 拉萨市| 海兴县| 岳阳县| 驻马店市| 武山县| 县级市| 册亨县| 织金县| 灵川县| 宝丰县| 农安县| 黎平县| 鹰潭市| 乡宁县| 澄迈县| 秀山| 尉犁县| 万宁市| 阜康市| 利辛县| 淳化县| 鲁山县| 海南省| 屯门区| 和顺县| 双城市| 河源市| 沧源|