zoukankan      html  css  js  c++  java
  • 动态获取当前时间,查询数据。

     1 HashMap<String,Object> paramMap =new HashMap<String,Object>();
     2             //获取当前时间
     3             SimpleDateFormat timesystem = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     4             Date date = new Date();
     5             
     6             String createDate = timesystem.format(date);
     7             paramMap.put("createDate", createDate);
     8             
     9             //获取当前月,确定表名
    10             SimpleDateFormat getmonth = new SimpleDateFormat("M");
    11             String month = getmonth.format(date);
    12             paramMap.put("month", month);
    13             
    14             //将当前时间减上一天,做条件查询
    15             Calendar calendar =Calendar.getInstance();
    16             calendar.setTime(date);
    17             calendar.set(Calendar.DATE, calendar.get(Calendar.DATE)-1);
    18             date= calendar.getTime();
    19             String beforetime = timesystem.format(date);
    20             paramMap.put("beforetime", beforetime);
    21             return this.thirdAPIService.listdhHistoryRoom(paramMap);
    22         }

    数据库SQL语句

     1  <select id="selectDhRoomHistory" parameterType="java.util.HashMap" resultType="java.util.LinkedHashMap">
     2         <![CDATA[
     3             select * from dh_room_history_${month} 
     4         ]]>
     5         <where>
     6         <if test ="beforetime != null">
     7             <![CDATA[ and createDate >= #{beforetime} ]]>
     8         </if>
     9         <if test ="createDate != null">
    10              <![CDATA[ and createDate <= #{createDate} ]]>
    11         </if>
    12         </where>
    13      </select>    
  • 相关阅读:
    965. 单值二叉树
    面试题 04.09. 二叉搜索树序列
    99. 恢复二叉搜索树
    98. 验证二叉搜索树
    centos6版本下的Python2.6升级到2.7
    操作MySQL-数据库的安装及Pycharm模块的导入
    操作微信-itchat库的安装
    2018中科大hackergame
    png图片IDAT块异常
    2018网鼎杯misc
  • 原文地址:https://www.cnblogs.com/fenghh/p/9724085.html
Copyright © 2011-2022 走看看