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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章