본문 바로가기

Java

Mybatis null 체크와 문자열 비교

 

Mybatis에서 null체크하는 법과 문자열 비교하는 법에 대해서 정리한다.

 

 

1. Mybatis Null 체크 공백 체크

<if test=" str != null and str != '' ">

<if test=" userName != null and !''.equals(userName) ">

SELECT 
    ID, NAME
FROM MEMBER
WHERE ID = #{id}
<if test="name != null and name != ''">
AND NAME = #{name}
</if>

 

2. Mybatis 문자열 비교

<if test=' "N".equals(status) '>
<if test=' str == "01" '>
<if test=' str == "N" '>

SELECT 
    ID, NAME
FROM MEMBER
WHERE 1=1
<if test='delYn == "N"'>
AND status = #{delYn}
</if>
<if test='str == "01"'>
AND STATUS = #{status}
</if>

 

반응형