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>

 

posted @   LowKeyC  阅读(1336)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
有志者事竟成破釜沉舟百二秦关终属楚苦心人,天不负,卧薪尝胆,三千越甲可吞吴
点击右上角即可分享
微信分享提示