步骤一:导入依赖

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

步骤二:application.properties文件

spring.thymeleaf.cache=fasle

步骤三:创建controller文件

@Controller
@RequestMapping("/index02")
public class index02Controller {

    @RequestMapping("/getOne")
    public String getOne(Model model){
        List<Student> list=new ArrayList<>();
        Student stu=new Student(1,"小明");
        Student stu1=new Student(2,"小红");
        list.add(stu);
        list.add(stu1);
        model.addAttribute("list",list);
        return "index02";
    }

}

步骤四:在templates文件夹下创建html页面  

    

  index02页面:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>页面</title>
</head>
<body>

<ul th:each="list:${list}">
    <li>
        <span th:text="${list.sid}"></span>
        <span th:text="${list.sname}"></span>
    </li>
</ul>

</body>
</html>

步骤五:实现结果

  

 

 

 posted on 2019-12-12 14:48  wnwn  阅读(209)  评论(0编辑  收藏  举报