:::: 개발 ::::/::: JAVA :::

마이바티스 IN 처리 (Mybatis IN )

nayha 2019. 8. 9. 17:56
반응형


처음 요구는 CD ='11' 이였는데
하다보니 다건 검색 .. 
아 이거 몇번 경험한건데 
처음 설계할때 항상 유연하게 처리하는 생각을 해야겠다  

여하튼 cd =#{cd} 에서 cd = IN('cd1','cd2') 로 변환시작

front 에서는
'cd1' 이걸 'cd1,cd2' 로 전달

JAVA 에서 req 


import java.util.ArrayList; 
import java.util.List; 

public class testMain { 
 public static void main(String[] args) { 
System.out.println("test"); 
System.out.println(makeForeach("DYTE0001,DYTE0002")); 
} 
  
public static List makeForeach(String code){ 
    String gb = ","; 
    return makeForeach(code, gb); 
} 
public static List makeForeach(String code, String gb){ 
      
    if (code == null || "".equals(code)) { 
        return null; 
    } 
      
    List codeList = new ArrayList(); 
      
    String[] aCode = code.split(gb); 
    for(int i=0; i< aCode.length; i++){ 
          
        codeList.add(aCode[i].toString()); 
    } 
  
    return codeList;        
} 
} 



결과 
test
[DYTE0001, DYTE0002]

----다시 web service --------------------

Map<String, Object> CD = new Map<String, Object>();
CD.put("CD",makeForeach(reqCD));

CD 마이바티스로 전달

MYBATIS code

WHERE 1=1

CD.size != 0">
AND CD IN 

#{item}




끝 잘됨

 

참고 tistory => https://farmerkyh.tistory.com/933 

반응형