您好,登錄后才能下訂單哦!
小編給大家分享一下JAVA實現按時間段查詢數據操作的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
html / jsp
<span >開始時間:</span> <input name="startTime" id="startTime" type="text" class="Wdate" onfocus="WdatePicker()" style="height: 34px; line-height: 34px; border-radius: 4px; border: 1px solid #ccc; font-size: 14px;"> <span class="ml10 mr8" >結束時間: </span> <input name="endTime" id="endTime" type="text" class="Wdate" onfocus="WdatePicker()" style="height: 34px; line-height: 34px; border-radius: 4px; border: 1px solid #ccc; font-size: 14px;"> <input type="submit" class="btn btn-query" id="findTime" value="查詢" onClick="toFindTime();" />
js方法:
function timeCheckInfo(page,startTime,endTime,officeVal){ var startTime=$("#startTime").val(); var endTime=$("#endTime").val(); $.ajax({ url: "../../security/base/peoplesafeimg!findPortFolioByTime.action", type: "post", data:{ pagenum:page, startTime:startTime, endTime:endTime, deptid:officeid, // 處室ID來源于默認(頁面傳值)和下拉框選擇 lenian 2018 06 29 depotid:depotid }, dataType: "json", success: function (data) { //alert(JSON.stringify(data)); var dataset = data[0].result; $(dataset).each(function(i,val) { }); }, error:function(){ alert("查詢數據失敗") } }); }
PeoplesafeimgAction.java
/** * @author lenian 2018 06 12 * 根據時間查詢人員畫像機務處、運輸處、貨運處工作量數據并展示 * @param page * @param startTime * @param endTime * @return */ public String findPortFolioByTime(){ page.setPageNo(pagenum); page = (Page<Map<String, Object>>) peopleSafeImgManager.getPortFolioByTime(page, startTime, endTime, deptid, depotid); JSONArray jsonArray = JSONArray.fromObject(page); renderTextJSONGBK(jsonArray.toString()); return null; } PeopleSafeImgManager.java /** * @author lenian 2018 06 12 * 根據時間查詢人員畫像機務處、運輸處、貨運處工作量數據并展示 * @param page * @param startTime * @param endTime * @return */ @SuppressWarnings("unchecked") public Page<Map<String, Object>> getPortFolioByTime(Page<Map<String, Object>> page, String startTime, String endTime, Long deptid, Long depotid) { String depotName = null; // 判斷當站段登錄時,傳到后臺的depotid為空 if (depotid == null) { Long depot_id = SessionManager.getDepartmentId(); Department department = departmentManager.getObjectById(depot_id); depotName = department.getName();//站段 } else if (depotid != null && depotid != 0) { // 當處室登錄,選擇其中某個站段進行了查詢 Department department = departmentManager.getObjectById(depotid); depotName = department.getName();//站段 } // 根據處室將數據區分開來 lenian 2018 06 25 Department deparent = departmentManager.getObjectById(deptid); // 當處室登錄,并且depotid==0,表示查詢所有(注:以上操作可示為參數的準備) String sql; if (depotid != null && depotid == 0) { sql = "select spp.id,\n" + " sei.name,\n" + " spp.id_card,\n" + " to_char(spp.time, 'yyyy-MM-dd') time,\n" + " spp.ins,\n" + " spp.outs,\n" + " spp.score,\n" + " spp.minute,\n" + " spp.column_number,\n" + " spp.channel_number\n" + " from Security_Portrait_Portfolio spp, Security_Employee_Info sei\n" + " where spp.id_card = sei.idcard_num(+) and sei.office_name = '"+ deparent.getName() +"'"; } else { // 1、當處室登錄,選擇其中某個站段進行了查詢; 2、站段登錄,獲取當前站段ID sql = "select spp.id,\n" + " sei.name,\n" + " spp.id_card,\n" + " to_char(spp.time, 'yyyy-MM-dd') time,\n" + " spp.ins,\n" + " spp.outs,\n" + " spp.score,\n" + " spp.minute,\n" + " spp.column_number,\n" + " spp.channel_number\n" + " from Security_Portrait_Portfolio spp, Security_Employee_Info sei\n" + " where spp.id_card = sei.idcard_num(+) and spp.depot = '"+ depotName +"' and sei.office_name = '"+ deparent.getName() +"'"; } if (StrUtils.stringQuery(startTime) && StrUtils.stringQuery(endTime)) { sql += "and to_char(spp.time, 'yyyy-MM-dd') between '"+ startTime +"' and '"+ endTime +"'"; } sql += "order by spp.create_time desc"; SQLQuery query = dao.getSession().createSQLQuery(sql); Integer count = Integer.parseInt(dao.getSession() .createSQLQuery("select count(1) from (" + sql + ")") .uniqueResult().toString()); if (page.isAutoCount()) { page.setTotalCount(count); } if (page.isFirstSetted()) { query.setFirstResult(page.getFirst()); } if (page.isPageSizeSetted()) { query.setMaxResults(page.getPageSize()); } query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); page.setResult(query.list()); return page; }
補充知識:Java 實現判斷時間是否在某個區間內(如是否在23點到凌晨4點之間)
最近遇到一個需求,就是判斷一個時間是否在23點到凌晨4點之間,這個時間段是可以修改的。在網上收了一下發現沒有符合我的需求的,就自己琢磨了一下,感覺這樣算還是可以的。
思路:
如上圖的那個圓形的鐘表,可以從開始時間剪斷,把鐘表的環鋪平,此時就變成了一個刻度尺,這樣就好比較了
代碼塊
測試代碼:
public static void main(String[] args) { int start = 23; int end = 4; int emp = 24 - start; for (int d = 0; d < 24; d++) { System.out.println((start + emp) % 24 + "\t" + (d + emp) % 24 + "\t" + (end + emp) % 24); } }
輸出:
0 1 5 0 2 5 0 3 5 0 4 5 0 5 5 0 6 5 0 7 5 0 8 5 0 9 5 0 10 5 0 11 5 0 12 5 0 13 5 0 14 5 0 15 5 0 16 5 0 17 5 0 18 5 0 19 5 0 20 5 0 21 5 0 22 5 0 23 5 0 0 5
看完了這篇文章,相信你對JAVA實現按時間段查詢數據操作的方法有了一定的了解,想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。