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') >= 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') <= str_to_date(#{endDate},'%Y-%m-%d %H:%i:%s')
</if>
</select>
以上加红色部分等同between...and...
cd.create_time between #{startDate} and #{endDate}