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

  • 相关阅读:
    tips
    数学建模-预测模型优缺(搬运)
    数学建模-灰色预测模型GM(1,1)_MATLAB
    Floyd算法_MATLAB
    第二章 运算方法与运算器(浮点数的加减法,IEEE754标准32/64浮点规格化数)
    面向对象
    for循环
    if---else
    airflow的web任务管理
    airflow原理
  • 原文地址:https://www.cnblogs.com/ZFnice/p/5706356.html
Copyright © 2011-2022 走看看