zoukankan      html  css  js  c++  java
  • SpringBoot使用thymeleaf模板

    步骤一:导入依赖

    <!-- 添加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>

    步骤五:实现结果

      

  • 相关阅读:
    单链表反转
    C++面试题
    堆排序
    1链表:回文链表(leetcode 234)
    深信服社招linux岗面试记录
    腾讯后台开发社招记录(电话面试)
    小米社招ATE岗位记录
    诺基亚社招C++面试记录
    腾讯后台开发社招面试记录
    makefile笔记
  • 原文地址:https://www.cnblogs.com/wnwn/p/12029125.html
Copyright © 2011-2022 走看看