最新消息:

Mybatis 异常:The content of elements must consist of well-formed character data or markup

SQL 观测者 3632浏览

今天用mybatis发现以下语句导致程序报错:

  1. <select id="query" parameterClass="java.util.HashMap"  
  2.         resultClass="com.company.cndw.yg.domain.YG02">  
  3.         SELECT stacking_no,            <!--码单号-->  
  4.                    rec_create_time,      <!--码单日期-->  
  5.                    stacking_wt             <!--码单量-->  
  6.           FROM SU.V_MES_SMDF65 WHERE '1'='1'  
  7.         <isNotEmpty prepend=" AND " property="stackingStartDate">  
  8.               rec_create_time >= #stackingStartDate#  
  9.         </isNotEmpty>  
  10.         <isNotEmpty prepend=" AND " property="stackingEndDate">  
  11.               rec_create_time <= #stackingEndDate#  
  12.         </isNotEmpty>  
  13.         <dynamic prepend="ORDER BY">  
  14.           <isNotEmpty property="orderBy">  
  15.               $orderBy$  
  16.           </isNotEmpty>  
  17.           <isEmpty property="orderBy">  
  18.               stacking_no asc  
  19.           </isEmpty>  
  20.         </dynamic>  
  21. </select>  

异常如下:SAXParseException: The content of elements must consist of well-formed character data or markup.

网上搜索之后得到一个匪夷所思的答案:在ibatis的配置文件中不能出现小于号。

于是将代码改为:

  1. <select id="query" parameterClass="java.util.HashMap"  
  2.         resultClass="com.company.cndw.yg.domain.YG02">  
  3.         SELECT stacking_no,            <!--码单号-->  
  4.                    rec_create_time,      <!--码单日期-->  
  5.                    stacking_wt             <!--码单量-->  
  6.           FROM SU.V_MES_SMDF65 WHERE '1'='1'  
  7.         <isNotEmpty prepend=" AND " property="stackingStartDate">  
  8.               rec_create_time >= #stackingStartDate#  
  9.         </isNotEmpty>  
  10.         <isNotEmpty prepend=" AND " property="stackingEndDate">  
  11.               rec_create_time <![CDATA[<]]>= #stackingEndDate#  
  12.         </isNotEmpty>  
  13.         <dynamic prepend="ORDER BY">  
  14.           <isNotEmpty property="orderBy">  
  15.               $orderBy$  
  16.           </isNotEmpty>  
  17.           <isEmpty property="orderBy">  
  18.               stacking_no asc  
  19.           </isEmpty>  
  20.         </dynamic>  
  21. </select>  

问题成功解决了。

转载请注明:观测者 » Mybatis 异常:The content of elements must consist of well-formed character data or markup