html / jsp
<span style="vertical-align: -webkit-baseline-middle;font-size:16px;font-weight:bold;">开始时间:</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" style="font-size:16px;font-weight:bold;">结束时间: </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();" style="float:none;"/>
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实现按时间段查询数据操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持呐喊教程。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。