栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

thymeleaf

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

thymeleaf

本来是不想记录的,但是发现现在的记性是越来越不好了,还是重新整理一遍笔记吧。

thymeleaf

创建springboot项目,然后把thymeleaf、lombok、web选上,删掉多余的几个文件。
创建实体类User如下:

import lombok.Data;
@Data
public class User {
    private Long id;
    private String name;
    private String address;
}

创建IndexController如下

import com.tobest.thymeleaf.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {
    @GetMapping("index")
    public String index(Model model){
        List users = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            User user = new User();
            user.setId((long) (i+1));
            user.setName("郑培烽");
            user.setAddress("地址");
            users.add(user);
        }
        model.addAttribute("users",users);
        return "index";
    }
}

在默认路径templates下面创建index.html




    
    测试


  
编号 用户名 地址

完成

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/294618.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号