参考
问题描述
调用接口时,报下面的错误
[target\classes\mapper\TbeEinvoiceinfoEntityMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 107; columnNumber: 48; 元素内容必须由格式正确的字符数据或标记组成。
问题分析
查看 TbeEinvoiceinfoEntityMapper.xml
<where><if test="1 == 1">EinvoiceInfo.IsDelete = 0 AND EinvoiceInfo.BillType = 0</if><if test="param.merchantGuid != null and param.merchantGuid != ''">AND EinvoiceInfo.MerchantGuid = #{param.merchantGuid}</if><if test="param.beginDate != null and param.beginDate != ''">AND EinvoiceInfo.EinvoiceTime >= #{param.beginDate}</if></where><if test="param.amountSort == null and param.amountSort == '' or param.amountSort == 0">ORDER BY CreateDate DESC</if>
错误原因:mybatis查询的时候,需要用到运算符 小于号:< 和 大于号: >,在mybatis配置文件里面,这种会被认为是标签,所以解析错误
问题解决
修改 TbeEinvoiceinfoEntityMapper.xml
有判断符号(>,<,>=,<=) 使用 <![CDATA[ ]]> 包围
<where><if test="1 == 1">EinvoiceInfo.IsDelete = 0 AND EinvoiceInfo.BillType = 0</if><if test="param.merchantGuid != null and param.merchantGuid != ''">AND EinvoiceInfo.MerchantGuid = #{param.merchantGuid}</if><if test="param.beginDate != null and param.beginDate != ''"><![CDATA[ AND EinvoiceInfo.EinvoiceTime >= #{param.beginDate} ]]></if></where><if test="param.amountSort == null and param.amountSort == '' or param.amountSort == 0">ORDER BY CreateDate DESC</if>
测试结果
添加后 <![CDATA[ ]]>,错误消失