Person对象
package com.example.demossmshiro.pojo;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @Author lyr
* @create 2020/2/7 1:08
*/
@Data
@Accessors(chain = true)
public class Person {
private Integer id;
private String password;
private String name;
}
产生person对象
package com.example.demossmshiro.util;
import com.example.demossmshiro.pojo.Person;
import org.apache.tomcat.util.buf.StringUtils;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/**
* @Author lyr
* @create 2020/2/7 1:09
*/
public class PersonFactory {
public static List<Person> getPersonList()
{
List<Person> arr = new LinkedList<>();
for (int i=0;i<10;++i)
{
Person p = new Person()
.setId(i)
.setName("hello"+i)
.setPassword(i+"ddxxxfasfa")
;
arr.add(p);
}
return arr;
}
}
配置 controller
package com.example.demossmshiro.controller;
import com.example.demossmshiro.util.PersonFactory;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @Author lyr
* @create 2020/2/7 1:06
*/
@Controller
public class IndexController {
@RequestMapping("/array")
public String arr(@org.jetbrains.annotations.NotNull Model m)
{
m.addAttribute("persons",PersonFactory.getPersonList());
return "array";
}
@RequestMapping("/index")
public String index()
{
return "index";
}
}
templates下面的 array.html
<!DOCTYPE html>
<html lang="zh" xlmns="http://www.thymeleaf.org" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div th:each="person : ${persons}">
<div th:text="${person}"></div>
</div>
</body>
</html>