Mybatis時間段比較


在開始時間和結束時間內的一段時間范圍的查詢

<if test="timeStart != null and timeStart != ''">
and wfsj &gt;= to_date(#{timeStart}, 'yyyy-MM-dd hh24:mi:ss')
</if>
<if test="timeEnd != null and timeEnd != ''">
and wfsj &lt; to_date(#{timeEnd}, 'yyyy-MM-dd hh24:mi:ss')
</if>

 

查詢某個月的

傳入的就是“2017-02”這種格式的。

<if test="lastMaintenance !=null and lastMaintenance !=''">
and to_char(last_maintenance,'yyyy-mm') = #{lastMaintenance}
</if>

 

//*************************月份選擇*easyui的datebox以月份展示

JSP:

<div class="m-form-cell">
<label for="search-box">維護時間:</label> <input type="text" id="datetime1" >
</div>

JS:
$(function() {
$('#datetime1').datebox({
onShowPanel : function() {// 顯示日趨選擇對象后再觸發彈出月份層的事件,初始化時沒有生成月份層
span.trigger('click'); // 觸發click事件彈出月份層
if (!tds)
setTimeout(function() {// 延時觸發獲取月份對象,因為上面的事件觸發和對象生成有時間間隔
tds = p.find('div.calendar-menu-month-inner td');
tds.click(function(e) {
e.stopPropagation(); // 禁止冒泡執行easyui給月份綁定的事件
var year = /\d{4}/.exec(span.html())[0]// 得到年份
, month = parseInt($(this).attr('abbr'), 10) + 1; // 月份
$('#datetime1').datebox('hidePanel')// 隱藏日期對象
.datebox('setValue', year + '-' + month); // 設置日期的值
});
}, 0);
},
parser : function(s) {// 配置parser,返回選擇的日期
if (!s)
return new Date();
var arr = s.split('-');
return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
},
formatter : function(d) {
var month = d.getMonth();
if(month<=10){
month = "0"+month;
}
if (d.getMonth() == 0) {
return d.getFullYear()-1 + '-' + 12;
} else {
return d.getFullYear() + '-' + month;
}
}// 配置formatter,只返回年月
});
var p = $('#datetime1').datebox('panel'), // 日期選擇對象
tds = false, // 日期選擇對象中月份
span = p.find('span.calendar-text'); // 顯示月份層的觸發控件

});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM