Back/Mybatis
Mybatis foreach에서 collection Map으로 가져오는 방법
밍꿔
2019. 12. 4. 11:35
반응형
파라미터로 넘길 collection 형태
ex) Map의 value에 또 HashMap을 선언한 경우
//Map 선언
private Map<String, HashMap<String, String>> fieldData = new HashMap<String, HashMap<String, String>>();
아래의 코드처럼 foreach에서 Map형태를 매핑하려면 entrySet()를 사용.
첫 번째 foreach에서 item의 element를 두 번째 foreach의 collection으로 연결.
// map.entrySet()
<foreach index="key" item="element" collection="fieldData.entrySet()" >
<foreach index="dtKey" item="dtElement" collection="element">
<if test="element[dtKey] != null and element[dtKey] != ''">
<choose>
<when test='dtKey == "4"'>
AND INSTR(FD.${key}, ',${element[dtKey]},') > 0
</when>
<otherwise>
AND FD.${key} = '${element[dtKey]}'
</otherwise>
</choose>
</if>
</foreach>
</foreach>
반응형