Springboot+Thymeleaf+BootStrap简单实现表格数据显示

Bootstrap组件链接:

https://v3.bootcss.com/components/

 

实现的页面效果

Springboot+Thymeleaf+BootStrap简单实现表格数据显示_第1张图片

 

Thymeleaf循环获取后台返回的对象数据

 

table.html源码




    
    数据表格页面
    
    
    



    
序号 用户名 密码 年龄 地址 电话 性别 操作

 

controller层 + 实体类

package com.ldgroup.ldtest.thymeleafbootstrap.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @Description
 * @Author by mocar小师兄
 * @Date 2020/4/8 22:38
 **/
@Controller
@RequestMapping("/test")
public class testController {

    //Thymeleaf    模板引擎返回页面
    @GetMapping("/table")
    public String table(Model model){
        List tables = new ArrayList<>();
        for (int i = 1; i < 10; i++) {
            table table = new table();
            table.setId(i);
            table.setUsername("张" + (1+i));
            table.setPassword("password" + (1+i));
            table.setAge(new Random().nextInt(30));
            table.setAddress("杭州");
            if (i%2 ==0){
                table.setGender(0);
            }else {
                table.setGender(1);
            }

            table.setPhone(new Integer((1000000 +new Random().nextInt(500000))).toString());
            tables.add(table);
        }
        model.addAttribute("tables",tables);
        return "table";
    }


    public static class table{
        private Integer id;
        private String username;
        private String password;
        private Integer age;
        private String address;
        private String phone;
        private Date birth;
        private Integer gender;

        public table() {
        }

        public Integer getGender() {
            return gender;
        }

        public void setGender(Integer gender) {
            this.gender = gender;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public Date getBirth() {
            return birth;
        }

        public void setBirth(Date birth) {
            this.birth = birth;
        }



        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public Integer getAge() {
            return age;
        }

        public void setAge(Integer age) {
            this.age = age;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getPhone() {
            return phone;
        }

        public void setPhone(String phone) {
            this.phone = phone;
        }

    }
}

 

 

你可能感兴趣的:(Springboot+Thymeleaf+BootStrap简单实现表格数据显示)