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')";
    }

  • 相关阅读:
    .Net中获取打印机的相关信息
    如何在windows server 2008上配置NLB群集
    jvm分析内存泄露
    JVM调优
    线程池工作队列饱和策略
    线程池的处理流程:
    Java的Executor框架和线程池实现原理(转)
    线程池实现原理详解:
    futer.get()(如果任务没执行完将等待)
    sql注入
  • 原文地址:https://www.cnblogs.com/ZFnice/p/5706356.html
Copyright © 2011-2022 走看看