코드 짜는 티모

mybatis에서 db xml 태그 사용 본문

IT/DB

mybatis에서 db xml 태그 사용

나무뒤에티모 2018. 12. 7. 23:58
반응형

mybatis에서 db xml 태그 사용


mybatis ibatis 에서는 동적 태그를 지원합니다.


-> 프로시저인 로직을 조건문을 넣어준 로직을 만들어 줄 수 있다.



ibatis에는 여러가지 태그가 있지만 mybatis에서는 이를 간단하게 조건문으로만 구현할 수 있다.


<ibatis 태그>


1
2
3
4
5
6
7
8
9
10
isNull
isNotNull
isEmpty
isNotEmpty
isGreaterThan
isGreaterEqual
isLessThan
isLessEqual
isEqual
isNotEqual



ex)


1
2
3

<isGreaterThan property="Property" compareValue="5">
    5보다 클경우 조건문
</isGreaterThan>





<mybatis 태그>


1
2
if : 단일 조건문일때
choose when otherwise : 다중조건문 



sql문처럼 다중조건을 넣어줄 수 있다.

단, && -> AND

     ||    -> OR


ex)

1
2
3
4
5
6
7
8
<choose>
    <when test="Property == null">
        NULL일경우 조건문
    </when>
    <otherwise>
        NULL이 아닐경우 조건문
    </otherwise>
</choose>




1
2
3
<if test="Property == ''">
    조건문
</if>
cs



1
2
3
<if test='Property > 5'>
    5보다 클경우 조건문
</if> 
cs


반응형
Comments