list,此代碼視爲僞代碼,單獨不能運行,僅僅記錄一下流程
/**
*
* 去重,整理,一個key多個value 此代碼視爲僞代碼,單獨不能運行,僅僅記錄一下流程
*
* map爲{img_path2=/bidAttachment/b10a3fe2-f25b-4ce2-91d6-89c69522edac.jpg,
* IMG_TITLE1=身份證,
* IMG_TITLE2=身份證,
* img_path1=/bidAttachment/92e10a0d-fd95-41d7-9dd8-610921e2cd1e.bmp,...}
*
* 轉爲[
{
房屋照片=[
/bidAttachment/92e10a0d-fd95-41d7-9dd8-610921e2cd1e.bmp
]
},
{
房產證=[
/bidAttachment/4f065ced-b828-4825-b886-054e5e232c6d.gif,
/bidAttachment/b10a3fe2-f25b-4ce2-91d6-89c69522edac.jpg
]
},...]
*/
public List<Map<String, List<String>>> swapMap(Map<String, String> m) {
List<Map<String, List<String>>> re = new ArrayList<Map<String, List<String>>>();
if (m.size() > 0) {
for (int i = 1; i <= 11; i++) {
boolean flag = true;
if (m.get("IMG_PATH" + i) != null
&& !"".equals(m.get("IMG_PATH" + i).toString())
&& m.get("IMG_TITLE" + i) != null
&& !"".equals(m.get("IMG_TITLE" + i).toString())) {
String tk = "IMG_TITLE" + i;
String tv = m.get(tk);
String ik = "IMG_PATH" + i;
String iv = m.get(ik);
for (Map<String, List<String>> map : re) {
if (map.containsKey(tv)) {
List<String> ivl = map.get(tv);
ivl.add(iv);
map.put(tv, ivl);
flag = false;
continue;
}
}
if (flag) {
Map<String, List<String>> rm = new HashMap<String, List<String>>();
List<String> ivlist = new ArrayList<String>();
ivlist.add(iv);
rm.put(tv, ivlist);
re.add(rm);
}
}
}
return re;
}
return null;
}
jsp,對List<Map<String,List<String>>>的遍歷
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<body>
<!-- 對List<Map<String,List<String>>> attachList 的遍歷 -->
<c:if test="${attachList!=null}">
<c:forEach items="${attachList}" var="attach">
<c:forEach items="${attach }" var="map">
${map.key }
</c:forEach>
<c:forEach items="${map.value}" var="imgelist">
${imgelist}
</c:forEach>
</c:forEach>
</c:if>
<!-- 或者 如果action中沒有進行null判斷,可以用list的大小判斷是否有值 -->
<c:if test="${fn:length(attachList)>0}">
<c:forEach items="${attachList}" var="attach">
<c:forEach items="${attach }" var="map">
${map.key }
</c:forEach>
<c:forEach items="${map.value}" var="imgelist">
${imgelist}
</c:forEach>
</c:forEach>
</c:if>
</body>
</html>