在controller中添加
@RequestMapping("list") public String list(Model model){ List<User> list = new ArrayList<User>(); User user1 = new User(); user1.setId(1); user1.setUsername("oyb"); user1.setPassword("123"); user1.setGender("男"); user1.setBirthday(new Date()); User user2 = new User(); user2.setId(2); user2.setUsername("oxm"); user2.setPassword("1232"); user2.setGender("男"); user2.setBirthday(new Date()); list.add(user1); list.add(user2); model.addAttribute("userList",list); return "/user/userlist"; }
写一个用户列表
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>用户列表</title> </head> <body> 用户列表 <table border="1"> <c:forEach items="${userList}" var="user"> <tr> <td>${user.username}</td> <td>${user.password}</td> <td>${user.gender}</td> <td>${user.birthday}</td> </tr> </c:forEach> </table> </body> </html>
测试
原文地址:https://www.cnblogs.com/ouyangbo/p/10658197.html
时间: 2024-10-23 12:54:38