728x90
SMALL
mybatis에서 collection을 사용해야하는데 만약 collection이 null이라면 다른 조건을 실행해야 할 때
if나 when을 써서 test ="info != null and info.size != 0" 이런식으로 하면 null check 완료
info는 collection 이름..
<select id="selectMrsEditListAll" resultType="java.util.HashMap" >
select
tcc.comm_nm as "rcy_cd"
,tfi.fclt_nm as "fclt_nm"
,th.old_val as "oldValue"
,th.new_val as "value"
,th.mdfy_resn AS "mdfy_resn"
,th.user_id AS "user_id"
,TO_CHAR(th.reg_date, 'yyyy-mm-dd') AS "reg_date"
from t_hist_life_mrs th
left join t_comm_cd tcc
on tcc.comm_code = th.sts_wst_type_cd
left join t_fclt_info tfi
on tfi.fclt_sn = th.fclt_sn
<choose>
<when test="info!=null and info.size!=0">
<trim prefix="WHERE">
<foreach collection="info" item="info" separator="or">
th.fclt_sn = #{info.fclt_sn}::int
</foreach>
</trim>
</when>
<otherwise>
<trim prefix="WHERE">
th.fclt_sn = 0
</trim>
</otherwise>
</choose>
order by reg_date desc
</select>
구구절절 쿼리 정말 맘에 안든다 ㅠ0ㅠ
728x90
LIST
'DB > mybatis' 카테고리의 다른 글
trim, prefix, prefixoverrides, suffix,suffixOverrides (0) | 2022.08.09 |
---|
댓글