프로그래밍/JAVA
Mybatis 에서 CDATA 사용하기
홍반장水_
2019. 8. 21. 16:37
반응형
Mybatis 사용시 쿼리문에 문자열 비교연산자나 부등호를 처리할 때가있습니다.
그러면 < 와 같은 기호를 괄호인지 아니면 비교연산자 인지 확인이 되지않아요.
이외에도 특수문자 사용하는데 제한이있습니다.
이럴때 사용한것이 <![CDATA[ 입니다.
<select id="findAll" resultMap="MemberResultMap">
select *
from employees
where salary > 100
</select>
CDATA 안에 들어가는 문장을 문자열로 인식하게 합니다.
<select id="findAll" resultMap="MemberResultMap">
<![CDATA[
select *
from employees
where salary > 100
]]>
</select>
조건태그에서
<select id="findAll" resultMap="MemberResultMap">
<![CDATA[
select *
from employees
where 1=1
]]>
<choose>
<when test='user_type != null and user_type =="1"'>
<![CDATA[
salary > 100
]]>
</when>
<otherwise>
<![CDATA[
salary < 100
]]>
</otherwise>
</choose>
</select>
반응형