본문 바로가기
개발/Java

[MyBatis] List를 이용하여 where문에서 in 처리

by 용술이 2022. 3. 28.
List 생성
public static List<String> listWhere(String code, String gb){
    List<String> codeList = new ArrayList<>();
     
    String[] strCode = code.split(value);
    for(int i=0; i< strCode.length; i++){
         
        codeList.add(strCode[i].toString());
    }
 
    return codeList;       
}

public void getCodes(List<String> codeList) { 
    Map<String, Object> search_map = new Map<String, Object>();
    List
    search_map.put("codeList", CommonUtil.listWhere(StringUtil.nullToStr("1001,1002,1003,1004"), "," ));

    commonDAO.selectList("codeInfo.selectCodeList", search_map); 
}

 

MyBatis 

 

<select id="selectCodeList"  resultType="codeMap">
    SELECT *
      FROM CODE
     WHERE code IN
     <foreach collection="codeList" item="code" index="index" separator="," open="(" close=")">
        #{code}
     </foreach>
</select>
반응형

댓글