Mybatis+Mysql一些事儿
Mybatis使用中,应注意的一些点
1.时间段查询
方法(1):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <if test="startTime != null and startTime != ''"> 2 AND sf.create_time <![CDATA[>=]]> STR_TO_DATE(#{startTime},"%Y-%m-%d %H:%i:%S") 3 </if> 4 <if test="endTime != null and endTime != ''"> 5 AND sf.create_time <![CDATA[<=]]> STR_TO_DATE(#{endTime},"%Y-%m-%d %H:%i:%S") 6 </if>
方法(2):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 a.create_time between 2 str_to_date(#{startTime,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%S') and 3 str_to_date(#{endTime,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%S') and
2.1 今天及以后的记录
AND TIMESTAMPDIFF(day,sf.create_time,NOW()) < -1
2.2 查询 1天前的记录
AND TIMESTAMPDIFF(day,sf.create_time,NOW()) > 0
2.3 查询 明日的记录
and TIMESTAMPDIFF(day,DATE_FORMAT(o.ext1_time, '%Y-%m-%d'),DATE_FORMAT(NOW(), '%Y-%m-%d'))=-1;
3.向**Mapper.xml传参超过2个参数时
方法(1):
Mapper.java接口中
Invention selectByDoctorId(String feedId,int doctorId);
Mapper.xml中
WHERE sfi.feed_id = #{0} AND sfi.doctor_id = #{1}
方法(2):封装到map中
Mapper.java接口中
List<OrderDetails> getOrderDetails(Map<String, Object> param);
Mapper.xml中
parameterType="HashMap"
#{startTime}