日期:2014-05-16  浏览次数:20374 次

jstl遍历list<map<user,list<cases>>>

最近项目需要搜索出全部的代理人信息及代理人的案例信息,展示到页面的效果如图:

?

?

以上结果展示出了代理人的相关信息,及这个人的案例信息。

?

/**
	 * 搜索保险代理人
	 * */
	@RequestMapping(value = "/search")
	public String indexSearch(ModelMap modelMap) {
		// 可以抽取出单独的方法
		UDBUserDao userDao = AppContext.getBean("userDao", UDBUserDao.class);
		CasesDao caseDao = AppContext.getBean("casesDao", CasesDao.class);
		String name = this.request.get().getParameter("searchname") == null ? ""
				: this.request.get().getParameter("searchname");
		int pageSize = AppUtils.getIntValue(CMConfig.getProperty("pageSize"));
		int currPageNum = AppUtils.getIntPage(this.request.get().getParameter(
				"page.currPageNum"));
		page.setCurrPageNum(currPageNum);
		page.setPageSize(pageSize);
		StringBuffer sql = new StringBuffer();
		sql.append("  and  name like '%").append(name).append("%'")
				.append(" and status & ").append(JournalDaily.STATUS_DELETED)
				.append(" != ")
				// 未删除
				.append(JournalDaily.STATUS_DELETED);
		page.init(AppConstant.DATABASE_SCHEMA_UDB_BB_USER + "."
				+ AppConstant.DATABASE_TABLE_UDB_USER,
				" CONVERT( name USING gbk ) COLLATE gbk_chinese_ci ", pageSize,
				page.getCurrPageNum(), sql.toString(), "");
		/* List<AccountUser> userlist = userDao.getSearchUser(name); */
		List<AccountUser> userlist = userDao.getSearchUser(page.getSQL());
		List<Map<AccountUser, List<Cases>>> usercases = new 
                ArrayList<Map<AccountUser, List<Cases>>>();
		for (AccountUser accountUser : userlist) {
			Map<AccountUser, List<Cases>> m = new HashMap<AccountUser, List<Cases>>();
			List<Province> provinces = AppProvinceAndCity.provinces;
			if (accountUser.getProvince() == null) {
				accountUser.setCityname("(尚未填写地区)");
			} else {
				for (Province province : provinces) {

					if (province.getCode() == accountUser.getProvince()) {
						accountUser.setCityname(province.getValue());
						break;
					}
				}
			}
			List<Cases> clist = caseDao.criteriaQueryByUserid(
					accountUser.getUid(), "  order by createtime desc");

			ArrayList<ListItem> list = AppConstant.INSURANCE_COMPANY;
			for (ListItem listItem : list) {
				if (accountUser.getCompany() == listItem.getKey()) {
					accountUser.setCompanyname(listItem.getValue());
					break;
				}
			}
			m.put(accountUser, clist);
			usercases.add(m);
		}
		modelMap.put("page", page);
		modelMap.put("searchname", name);
		modelMap.put("usercases", usercases);
		this.model.get().addAttribute("title",
				"搜索_" + CMConfig.getProperty("default.title"));
		return "search/search";
	}

?

List<Map<AccountUser, List<Cases>>> usercases = new ArrayList<Map<AccountUser, List<Cases>>>();

?

?? 注意:map 是无序插入数值的,跟list不同,如果采用map封装值的话,你会发现页面展示时候排序凌乱,而且每次访问都是不同的结果。

?

所以要封装到List里面,这就涉及到如何遍历问题。

?

遍历List 结果为map,map为 map<accountUser,List<cases>>

?

key,和value都是封装的,所以还需要遍历。

?

?

?

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/includes.jsp"%>
<%@ include file="/WEB-INF/view/header.jsp"%>
<%
	String path = request.getContextPath();
%>
<!--nav-->
<div id="nav_wrap">
	<ul id="nav">
		<li></li>
		<li></li>
	</ul>
</div>
<!--nav end-->

<!--search_content-->
<div id="search_content">
	<div class="search_type">
		<form action='<spring:url value="/search"></spring:url>' method="post">
			<input type="text" value="${searchname}" class="search_text"
				name="searchname" /> <input type="submit" value="搜索"
				class="search_button" />
		</form>
	</div&g