[IBATIS] 아이바티스 쿼리 작성시 유의사항, com.ibatis.common.xml.NodeletException, Error parsing XML
논리연산자를 아무렇게나 사용하면 에러가 납니다.
왜냐면 XML파일이기 때문이죠.
GREATER나 LESS를 쓰면 태그로 인식하는것입니다.
<![CDATA[ STRING ]]> 으로 쿼리 전체를 감싸도 됩니다.
이것때문에 파일이 깨지면 컴파일이 안되서 길쭉한 에러를 보게됩니다.
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.
Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup.
적용방법
<= : <![CDATA[ <= ]]>
=> : <![CDATA[ => ]]>
< : <![CDATA[ < ]]>
> : <![CDATA[ > ]]>
=> : <![CDATA[ => ]]>
< : <![CDATA[ < ]]>
> : <![CDATA[ > ]]>
샘플
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="QueryManager">
<select id="sampleQuery1" resultClass="java.util.HashMap">
SELECT * FROM (
SELECT ROWNUM AS RNUM, COL1, COL2, COL3, COL4 FROM BOARD
ORDER BY COL1 ASC, COL2 DESC
) WHERE RNUM <![CDATA[ <= ]]> #START# ORDER BY COL1 DESC, COL2 ASC
</select>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="QueryManager">
<select id="sampleQuery1" resultClass="java.util.HashMap">
SELECT * FROM (
SELECT ROWNUM AS RNUM, COL1, COL2, COL3, COL4 FROM BOARD
ORDER BY COL1 ASC, COL2 DESC
) WHERE RNUM <![CDATA[ <= ]]> #START# ORDER BY COL1 DESC, COL2 ASC
</select>
<select id="sampleQuery2" resultClass="java.util.HashMap" parameterClass="java.util.HashMap">
SELECT COUNT(*) AS TOTAL FROM BOARD
</select>