jsp查询页面:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>list</title> </head> <body> <c:forEach items="${userlist}" var="um"> -----${um.value.userName} -----${um.value.password} -----${um.value.position} -----${um.value.email} <br/> </c:forEach> </body> </html>
实体类:User
package cn.bdqn.pojo; public class User { private String userName; private String password; private String position; private String email; public User(String userName,String password,String position,String email){ super(); this.userName = userName; this.password = password; this.position = position; this.email = email; } 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 String getPosition() { return position; } public void setPosition(String position) { this.position = position; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
控制器:
@Controller @RequestMapping("/user") public class UserController { private Map<String, User> userList= new HashMap<String, User>(); //添加数据 public UserController() { userList.put("hl", new User("hl","123456","部门经理","[email protected]")); userList.put("zs", new User("zs","123456","质量经理","[email protected]")); userList.put("zw", new User("zw","123456","开发工程师","[email protected]")); userList.put("ly", new User("ly","123456","实施顾问","[email protected]")); } @RequestMapping(value="/userlist",method=RequestMethod.GET) public String list(Model model){ model.addAttribute("userlist",userList); return "user/list"; } }
时间: 2024-10-07 07:10:30