mybatis 为什么没有智能忽略and
<iftest="dateStart!=nullanddateStart!=''">ANDcDate>=concat(#{dateStart},'00:00:00')</...
<if test="dateStart != null and dateStart != ''">
AND cDate >= concat(#{dateStart},' 00:00:00')
</if>
<if test="dateEnd != null and dateEnd != ''">
<![CDATA[
AND cDate <= concat(#{dateEnd},' 23:59:59')
]]>
</if>
如果第一个条件为空的话 执行的sql语句 select * from table where AND cDate <= concat(#{dateEnd},' 23:59:59')
为什么没有把and 忽略掉呢
<where>
...
<if test="dateStart != null and dateStart != ''">
AND cDate >= concat(#{dateStart},' 00:00:00')
</if>
<if test="dateEnd != null and dateEnd != ''">
<![CDATA[
AND cDate <= concat(#{dateEnd},' 23:59:59')
]]>
</if>
</where>
如果最后一个查询条件不为空,之前的都为空,and 就忽略不掉,sql语句就会select * from table where and cDate <= 2014-01-01 23:59;59 展开
AND cDate >= concat(#{dateStart},' 00:00:00')
</if>
<if test="dateEnd != null and dateEnd != ''">
<![CDATA[
AND cDate <= concat(#{dateEnd},' 23:59:59')
]]>
</if>
如果第一个条件为空的话 执行的sql语句 select * from table where AND cDate <= concat(#{dateEnd},' 23:59:59')
为什么没有把and 忽略掉呢
<where>
...
<if test="dateStart != null and dateStart != ''">
AND cDate >= concat(#{dateStart},' 00:00:00')
</if>
<if test="dateEnd != null and dateEnd != ''">
<![CDATA[
AND cDate <= concat(#{dateEnd},' 23:59:59')
]]>
</if>
</where>
如果最后一个查询条件不为空,之前的都为空,and 就忽略不掉,sql语句就会select * from table where and cDate <= 2014-01-01 23:59;59 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询