mybatis 사용 시 문자, 문자열, 숫자 비교 방법이 모두 다르니 주의한다.
문자비교
<if test="data.equals('A')">
문자열비교
<if test='data.equals("A")'>
숫자비교
<if test='data == 1'>
mybatis를 이용하여 if문, choose문을 이용해 쿼리 자체를 선택실행시킬 수 있다..
조건문을 잘못 작성하는 등 if문에 걸리지 않고 모두 통과되어 버린다면 실행할 쿼리가 없어 mybatis query was empty
에러가 발생할 수 있음.
이럴 경우 choose문으로 변경한 후 when으로 분기를 설정한 후 맨 마지막에 아무 분기도 타지 않았을때 실행할 otherwise문을 설정해주면 됨.
단, if문의 조건에서 문제가 있어 의도한 대로 쿼리가 선택실행되지 않고 모조리 통과해버리는 상황일 확률이 높으니 조건문을 제대로 작성했는지를 확인한다.
<select>
<if test='data.equals("user")'>
select * from usertable where state = 'Y'
</if>
<if test='data.equals("manager")'>
select * from managertable where state = 'Y'
</if>
</select>
<select>
<choose>
<when test='data.equals("user")'>
select * from usertable where state = 'Y'
</when>
<otherwise>
select * from managertable where state = 'Y'
</otherwise>
</choose>
</select>