본문 바로가기

Struts2 + iBatis

[iBatis/MyBatis에러] Caused by: org.xml.sax.SAXParseException: Element type "if" must be declared.

 

Caused by: org.xml.sax.SAXParseException: Element type "if" must be declared.

다음과 같은 에러가 난다면, 아래를 고민해보자.

 

에러가 발생한 xml 파일을 열어보아서 <if> 태그가 있는지 확인해보자.

<if> 혹은 <forEach> 태그는 MyBatis2까지는 존재하지 않는다. (iBatis도 물론 존재하지 않는다)

 

 

  • <if> 는 <isEqual> 혹은 <isNotNull> 로 대체
    •   특정 값이 아닌, null인지 아닌지만 비교하고 싶을 때는 <isNotNull> 혹은 <isNull> 태그 이용.
  • <forEach> 는 <iterator> 로 대체해서 사용

 

 

에러가 난 코드

<if test="USER_NM != null and USER_NM != ''">
	USER_NM = #USER_NM#
</if>

 

수정 후

		 <isNotNull property="USER_NM">
		 	AND USER_NM = #USER_NM#
		 </isNotNull>

 

'Struts2 + iBatis' 카테고리의 다른 글

MyBatis 에서 #{} 과 ${}의 차이  (0) 2020.11.03
Interceptor (미)  (0) 2019.10.22