mybatis와 ibatis에서는 동적태그
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
출처 : http://hellogk.tistory.com/100
우선 mybatis와 ibatis에서는 동적태그를 기본적으로 지원을 합니다.
즉, 프로시저로 짜여져 있는 로직을 동적태그를 사용하여 쿼리로 변경할 수 있습니다.
장점이 있을수도 있지만 자칫 잘못 사용하면 큰 문제를 일으킬수 있다는 단점이있을수 있다는...
양날의 칼날과 같다는것만 알아두시면 되겠습니다.
ibatis 비교문 지원 태그
isNull : "널일경우"
isNotNull : "널이아닐경우"
isEmpty : "공백일경우"
isNotEmpty : "공백이아닐경우"
isGreaterTan : ">"
isGreaterEqual : ">="
isLessThan : "<"
isLessEqual : "<="
isEqual : "=="
isNotEqual : "!="
mybatis 비교문 지원 태그
if : 단일조건문
choose when otherwise : 다중조건문
위와같이 각 mybatis(ibatis) 별 동적태그를 지원합니다.
ibatis에 비해 mybatis의 비교문태그가 간단해졌습니다.
ibatis에서 지원되는 태그들 if문과 choose문만을 이용하여 비교가 가능해 진것이죠.
일반 자바코드와 ibatis/mybatis 별로 비교문 예를 들어보도록 하겠습니다.
Null 비교문
1 2 3 | if(stringProperty == null) { // code here} |
1 2 3 4 5 6 7 8 | <!--ibatis --><isNull property="stringProperty"> 조건문 </isNull><!--mybatis--><if test="stringProperty == null"> 조건문</if> |
NOT NULL 비교문
1 2 3 | if(stringProperty != null) { // code here} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!--ibatis --><isNotNull property="stringProperty"> 조건문 </isNotNull><!--mybatis(1)--><if test="stringProperty != null"> 조건문</if><!--mybatis(2)--><choose> <when test="stringProperty == null"> NULL일경우 조건문 </when> <otherwise> NULL이 아닐경우 조건문 </otherwise></choose> |
공백일경우 비교문
1 2 3 | if(stringProperty.equals("")) { //code here} |
1 2 3 4 5 6 7 8 | <!--ibatis--><isEmpty property="stringProperty"> 조건문</isEmpty><!--mybatis--><if test="stringProperty == ''"> 조건문</if> |