org.xml.sax.SAXParseException:the content of elements must consist of well-formed character data or

本来想在@select注解中使用动态拼接sql,我的代码中的select注解如下:

@Select({"<script>"
			+ "select count(if(ta.dt_created>=#{currentDate},true,null)) currentVolume,"
			+ "count(if(ta.dt_created<#{currentDate},true,null)) beforeVolume,Count(*) as volume"
			+ "where 1=1"
			+ "<if test='finalDecision != null'>"
			+ "and ta.final_decision=#{ finalDecision}"
			+ "</if>"
			+ "</script>"})

启动项目,报错如下:
ERROR org.mybatis.spring.mapper.MapperFactoryBean checkDaoConfig-82 – Error while adding the mapper ‘interface com…mapper.***Mappper’…
Caused by:org.xml.sax.SAXParseException:the content of elements must consist of well-formed character data or markup.
大概意思就是元素的内容必须由格式良好的字符数据或标记组成。刚开始以为不能动态拼接呢。。差点放弃改用xml了,最后仔细看想起来是mybatis的sql规范问题。我的sql中又大于小于符号,对于mybatis的sql中不能直接使用>、<这种符号。
改法1:<![CDATA[ > ]]>、<![CDATA[ < ]]>
改法2: < <= > >= & ’ " 依次替换成 &lt; &lt;= &gt; &gt;= &amp; &apos; &quot;
下边是我改的成品:

@Select({"<script>"
			+ "select count(if(ta.dt_created &gt;= #{currentDate},true,null)) currentVolume,"
			+ "count(if(ta.dt_created &lt; #{currentDate},true,null)) beforeVolume,Count(*) as volume"
			+ "where 1=1"
			+ "<if test='finalDecision != null'>"
			+ "and ta.final_decision=#{ finalDecision}"
			+ "</if>"
			+ "</script>"})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值