版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Dreamfirefly/article/details/78476454
今天把原来的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') >= #{start}
</if>
<if test="stop != null and stop != 'undefined' and stop != ''">
AND date_format(gather_time,'%Y-%m') <= #{stop}
</if>
这下就可以顺利执行了。