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

  • 相关阅读:
    WPF--模板选择
    C#基础知识回顾--委托事件
    WPF刷新界面之坎坷路
    git 复位出现If no other git process is currently running, this probably means a git process crashed in this repo
    winrar 授权破解过期解决
    百度地图经纬度批量查找功能XGeocoding使用手册
    variant conversion error for variable v23
    oracle exp导出加上过滤条件
    office 格式刷双击无法启用连刷模式
    xsl 文件如何定义 Javascript 函数并且调用
  • 原文地址:https://www.cnblogs.com/ZFnice/p/5706356.html
Copyright © 2011-2022 走看看