SQL 조건절 IN 안에 조건 여러개 넣기

마이바티스로

IN 조건절 안에 조건 여러개 넣는 방법



<application-properties.xml>

1
2
3
<!-- 영업팀 ID -->
<entry key="salesTeam">M0020,M0022,M0033</entry>
 
cs



<Controller.java>

1
2
3
4
5
6
7
8
9
/* 영업팀 ID 정보 */
@Value("#{config[salesTeam]}")
private String salesTeam;
 
~~중간생략~~
 
/* 영업팀 토큰 정보 가져오기 */
String[] salesTeamArray = salesTeam.split(",");
 
List<HashMap<StringString>> salesTeamTokenInfo = pushService.getSalesTeamTokenInfo(salesTeamArray);
cs



<Service.java>

1
2
3
public List<HashMap<StringString>> getSalesTeamTokenInfo(String[] salesTeamArray) {
    return pushMapper.getSalesTeamTokenInfo(salesTeamArray);
}
cs



<Mapper.xml>

1
2
3
4
5
6
7
8
9
10
11
12
13
<select id="getSalesTeamTokenInfo" parameterType="list" resultType="HashMap">
    SELECT A.TOKEN,
           B.DEVICE
      FROM 테이블에이 A,
           테이블비 B
     WHERE 조인조건
       AND A.MEM_IDX IN
       <foreach collection="array" item="memIdx" index="index" open="(" separator="," close=")">
       #{memIdx}
       </foreach>    
</select>
cs


+ Recent posts