zoukankan      html  css  js  c++  java
  • 当需要查询时间差来获取数据时

    首先list页面

    <td>数据库入库时间 : <input name="startime" type="text" style=" 157px" readonly="readonly" id="startime" maxlength="50" value="${startime}"onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});"style=" 180px;" /><input name="endtime" type="text"readonly="readonly" style=" 157px" id="endtime" maxlength="50"value="${endtime}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});"style="180px;" /></td>

    这段话里的WdatePicker是一个日历插件

    controller里边 接收一下

     String startime = request.getParameter("startime");
     String endtime = request.getParameter("endtime");

    再进行sql更改

    下面的三个方法都可以查本天。

    一.先介绍一个很普通的方法

    if(startime != null && !"".equals(startime) && endtime != null && !"".equals(endtime)){
    hql +=" and u.refresh_time >=to_date('" + startime + " 00:00:00'" + " ,'yyyy-mm-dd hh24:mi:ss') and u.refresh_time <=to_date('" + endtime + " 23:59:59'" + ",'yyyy-mm-dd hh24:mi:ss')";
    }


    二 .如果 要查询的是 组合时间 那么就用下边这个,但是
    if (startime != null && !"".equals(startime) && endtime != null && !"".equals(endtime)) { 2 sql += " and u.refresh_time between to_date('" + startime + " 00:00:00'" + " ,'yyyy-mm-dd hh24:mi:ss') and to_date('" + endtime + " 23:59:59'" + ",'yyyy-mm-dd hh24:mi:ss')"; 3 }

    三.如果想灵活多用那么就用 下面这个方法

    if(StringUtils.isNotBlank(start)&&StringUtils.isBlank(end)){
    hql +=" and g.clrq>=to_date("+"'"+start+"'"+",'yyyy-mm-dd')";
    }else if(StringUtils.isNotBlank(end)&&StringUtils.isBlank(start)){
    hql +=" and g.clrq<=to_date("+"'"+end+"'"+",'yyyy-mm-dd')";

    }else if(StringUtils.isNotBlank(start)&&StringUtils.isNotBlank(end)){
    hql +=" and g.clrq>=to_date("+"'"+start+"'"+",'yyyy-mm-dd') and g.clrq<=to_date("+"'"+end+"'"+",'yyyy-mm-dd')";
    }

  • 相关阅读:
    第十周作业
    第九周编程作业与总结
    第八周编程作业及总结
    第七周编程总结
    第五周课程总结&试验报告(三)
    第四周课程总结&试验报告(二)
    第三周学习总结
    Java第二周学习总结
    2019年学习总结
    第十二周作业
  • 原文地址:https://www.cnblogs.com/ZFnice/p/5706356.html
Copyright © 2011-2022 走看看