mybatis日期查询

默认查询7天的数据

<if test="startDate != null and startDate !='' ">
            <![CDATA[AND a.use_date >= #{startDate}]]>
        </if>
        <if test="endDate != null and endDate !='' ">
            <![CDATA[AND a.use_date < #{endDate}]]>
        </if> 
        <if test='startDate == null and endDate == null' >
            AND DATE_SUB(CURDATE(),INTERVAL 7 DAY) &lt;= a.use_date
        </if>

默认查询昨天的数据

<if test='startDate == null and endDate == null' >
            AND TO_DAYS( NOW( ) ) - TO_DAYS( a.dept_kpi_date) = 1
        </if>

参考:

http://www.cnblogs.com/qinweizhi/p/5918048.html

if判断参数等于某个值

<if test=' type == "1"'>....</if>

你可能感兴趣的:(mysql,mybatis)