본문 바로가기
기술(technology)/Mybatis

mybatis null 체크, 문자비교, 문자열 비교

by shinPro 2021. 9. 3.
반응형

1. null 체크

<if test='id neq null and id neq ""'>
     and table_name.id = #{id}
</if>

<if test='id != null and id neq ""'>
     and table_name.id = #{id}
</if>

<if test='id != null and !"".equals(id)'>
     and table_name.id = #{id}
</if>

2. 문자비교

<if test=" 'idName'.equals(id)">
     and a.idName = #{id}
</if>

2. 문자열비교

<!-- equalsIgnoreCase -->
<if test=" 'code'.equalsIgnoreCase(id)">
     and table_name.id = #{id}
</if>

<!-- == 연산자 사용 -->
<if test=" id == 'code'.toString()">
     and table_name.id = #{id}
</if>

<!-- eq 사용 -->
<if test=" id eq 'code'.toString()">
     and table_name.id = #{id}
</if>

 

 

반응형

댓글