개발 & 데이터베이스/JAVA

MyBatis 동적 쿼리 if문 문법 정리

K.두부 2024. 5. 28. 16:28
반응형

 

if 태그 안에서는 '<, >' 와 같은 부등호를 XML Pasing 으로 인식하기 때문에 적용이 되지 않는다. 

기호 대체문자 예제
< lt <if test="param lt 5">
> gt <if test="param gt 5">
<= lte <if test="param lte 5">
>= gte <if test="param gte 5">

 

or, and 문도 ||, && 가 아닌 or, and 문자 형식으로 사용해야한다.

기호 대체문자 예제
|| or <if test="param lt 5 or param gt 0">
&& and <if test="param lt 5 and param2 lt 1">

 

 

null, nullString 체크 같은 경우에는 아래와 같이 쓴다.

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

 

반응형