mybatis中between...and...语句的写法和详解

1、mybatis中xml文件中写法

<select id="selectByBrandChannel"  resultMap="BaseResultMap">
    SELECT
    ct.*,
    cd.*
    FROM
    coupon_detail cd
    LEFT JOIN coupon_template ct ON cd.template_id = ct.template_id
    <if test="brandChannel!=null and brandChannel!=''">
        where cd.brand_channel=#{brandChannel}
    </if>
    <if test="startDate!=null and startDate.trim() neq ''">
        and date_format(cd.create_time,'%Y-%m-%d %H:%i:%s') &gt;= str_to_date(#{startDate},'%Y-%m-%d %H:%i:%s')
    </if>
    <if test="endDate!=null and endDate.trim() neq ''">
        and date_format(cd.create_time,'%Y-%m-%d %H:%i:%s') &lt;= str_to_date(#{endDate},'%Y-%m-%d %H:%i:%s')
    </if>
</select>

以上加红色部分等同between...and...

cd.create_time  between #{startDate} and #{endDate}

 

上一篇:从零开始学SQLSERVER-BETWEEN


下一篇:java Period计算日期(LocalDate)