Java mybatis日期比较查询

public static SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
public static SimpleDateFormat format1 = new SimpleDateFormat(
"yyyyMMdd HH:mm:ss");



/**
* 得到指定日期的一天的的最后时刻23:59:59
*
* @param date
* @return
*/
public static Date getFinallyDate(Date date) {
String temp = format.format(date);
temp += " 23:59:59";

try {
return format1.parse(temp);
} catch (Exception e) {
return null;
}
}

/**
* 得到指定日期的一天的开始时刻00:00:00
*
* @param date
* @return
*/
public static Date getStartDate(Date date) {
String temp = format.format(date);
temp += " 00:00:00";

try {
return format1.parse(temp);
} catch (Exception e) {
return null;
}
}


<sql id="selectAcShareinfoScoreHistoryVo">
select share_id,inout_account_type, userName, phone, user_uuid, userName_to, phone_to,
type, del_flag, create_by, create_time,
update_by, update_time, score, score_show from ac_shareinfo_score_history
</sql>

<select id="selectAcShareinfoScoreHistoryList" parameterType="AcShareinfoScoreHistory" resultMap="AcShareinfoScoreHistoryResult">
<include refid="selectAcShareinfoScoreHistoryVo"/>
<where>
<if test="username != null and username != ''"> and userName like concat('%', #{username}, '%')</if>
<if test="phone != null and phone != ''"> and phone = #{phone}</if>
<if test="userUuid != null and userUuid != ''"> and user_uuid = #{userUuid}</if>
<if test="usernameTo != null and usernameTo != ''"> and userName_to = #{usernameTo}</if>
<if test="phoneTo != null and phoneTo != ''"> and phone_to = #{phoneTo}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="score != null and score != ''"> and score = #{score}</if>
<if test="scoreShow != null and scoreShow != ''"> and score_show = #{scoreShow}</if>
<if test="inout_account_type != null and inout_account_type != ''"> and inout_account_type = #{inout_account_type}</if>

<if test="createTime != null">
AND date_format(create_time,'%y%m%d') >= date_format(#{createTime},'%y%m%d')
</if>
<if test="updateTime != null">
AND date_format(#{updateTime},'%y%m%d') >= date_format(create_time,'%y%m%d')
</if>

</where>
</select>

 

<select id="selectCount" parameterType="NtcodeScaninfo" resultMap="NtcodeScaninfoResult">
select COUNT(s.scaninfoid) as count
from ntcode_scaninfo s
<!-- LEFT JOIN ntcode_antiepidemicpstaff a ON s.scanuuid=a.idcard-->
LEFT JOIN ntcode_position p ON s.positionid=p.positionid
LEFT JOIN ntcode_county cou ON p.countyid=cou.countyid
LEFT JOIN ntcode_town tow ON p.townid=tow.townid
<where>
<if test="createTime != null ">
and date_format(s.create_time,'%Y-%m-%d') = date_format(#{createTime},'%Y-%m-%d')
</if>
</where>
</select>
再牛逼的梦想,也抵不住我傻逼似的坚持!别在该奋斗的年纪,贪图安逸。 今天多学一些知识,明天开发的速度就更快一下。后天你就会变得更好。
原文地址:https://www.cnblogs.com/LowKeyCXY/p/14836000.html