xml里写sql语句大于、小于的正确方法

今天把原来的xml里的选择时间段内的方法改了一下,原来写的是在两个时间之间,用between … and …,这样做的话,两个参数,起始日期和终止日期必须都要输入,不能满足查询某个时间之前,或者之后的功能,于是我就想改成下面这样:

<if test="start != null and start != 'undefined' and start != ''">
    AND date_format(gather_time,'%Y-%m') >= #{start}                                    
</if>
<if test="stop != null and stop != 'undefined' and stop != ''">
    AND date_format(gather_time,'%Y-%m')  <=  #{stop}
</if>

但是无法执行,后来查资料知道是xml的格式问题,在xml里,不能用 < , >,= 之类的符号。一般都是用下面的字符来代替<、>、=,如下所示:

在这里插入图片描述

所以上面的sql语句应该这样写:

<if test="start != null and start != 'undefined' and start != ''">
    AND date_format(gather_time,'%Y-%m') &gt;= #{start}                                     
</if>
<if test="stop != null and stop != 'undefined' and stop != ''">
    AND date_format(gather_time,'%Y-%m') &lt;= #{stop}
</if>

这下就可以顺利执行了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值