티스토리 뷰
select *
from dual
<where> a
<if test="num != null and num != ''">
</if>
</where>
출처: http://cofs.tistory.com/97 [CofS]
이 글은 아래 블로그에서 발췌하였습니다.
출처: http://cofs.tistory.com/97 [CofS]
이슈 예제>
SELECT*
FROM dual
<where>
<if test=" num != null and num != '' ">
</if>
</where>
위와 같을 때 num 변수에 integer type의 0 값이 들어 있다면 num != '' 에서 같다고 판단한다.
이유는
OGNL(Object Graph Navigation Language) 의 문제일 것이라고 예상한다.
http://cofs.tistory.com/96 와 비슷한 문제일 수 있음(불확실)
- 해결방법
1. num을 string type으로 전송받는다
2. num != '' 대신에 num.equals("") 사용
3. 커스텀 static 함수 생성 및 사용 [추천 !!!!]
- 해결방법
1. num을 string type으로 전송받는다
2. num != '' 대신에 num.equals("") 사용
3. 커스텀 static 함수 생성 및 사용 [추천 !!!!]
출처: http://cofs.tistory.com/97 [CofS]
위와 같을 때 num 변수에 integer type의 0 값이 들어 있다면 num != '' 에서 같다고 판단한다.
이유는
OGNL(Object Graph Navigation Language) 의 문제일 것이라고 예상한다.
http://cofs.tistory.com/96 와 비슷한 문제일 수 있음.... test 해보지는 않았음.
출처: http://cofs.tistory.com/97 [CofS]
- 해결방법
1. num을 string type으로 전송받는다
2. num != '' 대신에 num.equals("") 사용
3. 커스텀 static 함수 생성 및 사용 [추천 !!!!]
출처: http://cofs.tistory.com/97 [CofS
package com.yudo.imc3;
import java.lang.reflect.Array;
import java.util.List;
import java.util.Map;
public class MybatisCheck {
/**
* Object type 변수가 비어있는지 체크
*
* @param obj
* @return Boolean : true / false
*/
@SuppressWarnings("rawtypes")
public static Boolean empty(Object obj) {
if (obj instanceof String) {
return obj == null || "".equals(obj.toString().trim());
}else if (obj instanceof List) {
return obj == null || ((List) obj).isEmpty();
}else if (obj instanceof Map) {
return obj == null || ((Map) obj).isEmpty();
}else if (obj instanceof Object[]) {
return obj == null || Array.getLength(obj) == 0;
}else {
return obj == null;
}
}
/**
* Object type 변수가 비어있지 않은지 체크
* @param obj
* @return Boolean : true / false
*/
public static Boolean notEmpty(Object obj) {
return !empty(obj);
}
}
사용법 (다이나믹 쿼리에서 호출
<if test="@test.com.MybatisCheck@notEmpty(num)">
</if>
<if test="@패키지.클래스@함수(파라미터)">
</if>