Jsp中遍历显示 List< Map> 的内容

Jsp中遍历显示  List<Map <String, Object > >的内容
		List<Map<String, Object>> listmap = adminService.getAllUser();
		List<User> userlist = new ArrayList<User>();
		for(Map<String ,Object>map : listmap) {	//遍历里面的map	
			User user = CommonUtils.toBean(map, User.class);	//使用小工具将map封装成javaBean
			userlist.add(user);
		}
		req.setAttribute("userlist",userlist);

Jsp中的代码

				<!-- 遍历用户集合信息 -->
                <c:forEach var="user" items="${userlist}">
	                <tr>
	                    <td>${user.userId}</td>
	                    <td>${user.username}</td>
	                    <td>${user.password}</td>
	                    <td>${user.actualName}</td>
	                    <td>${user.roleName}</td>
	                    <td>${user.sex}</td>
	                    <td>${user.phone}</td>
	                    <td>
	                    	<c:if test="${user.userId ne 1}">		<!-- 如果是超级管理员则没有删除 -->
	                    		<a href="#" onclick="delConfirm(${user.userId})">删除</a>&nbsp;|&nbsp;
	                    		<a href="GetUserServlet?Mod_userId=${user.userId}">编辑</a>		
	               			</c:if>
	               		</td>
	                </tr>																		
	                
                </c:forEach>

Service层中的代码

	public List<Map<String, Object>> getAllUser() throws SQLException {
		return adminDao.getAllUser();
	}

Dao层中的代码

	public List<Map<String, Object>> getAllUser() throws SQLException{
		String sql = "select * from t_user";
		List<Map<String, Object>> mapList = qr.query(sql, new MapListHandler());
		return mapList;
	}

猜你喜欢

转载自blog.csdn.net/duanbaoke/article/details/86000537