效果:

页面的数据准备:

     Map<String, String> map = findresult(type, date);List<StatisticsInterrogate> list = statisticsService.StatisticsInterrogatelist(map);request.setAttribute("StatisticsResult", list);

这里的JavaBean:

public class StatisticsInterrogate implements Serializable{private static final long serialVersionUID = 8738708908641883840L;/** 用户ID */private Long id;/** 用户姓名*/private String name;/** 提问数*/private int sumQuestion;public Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getSumQuestion() {return sumQuestion;}public void setSumQuestion(int sumQuestion) {this.sumQuestion = sumQuestion;}}

sql对应的.xml

<select id="StatisticsInterrogatelist" resultMap="StatisticsInterrogate"parameterType="map"><![CDATA[select u,t.name,count from(select userid u,count(userid) count from T_QUESTION t where]]><if test="type =='month'"><![CDATA[to_char(createtime,'YYYYMM') = #{date} ]]></if><if test="type =='year'"><![CDATA[to_char(createtime,'YYYY') = #{date} ]]></if><![CDATA[group by userid  ) left join(select id,name from T_USER) t on u = t.id where rownum<=20 order by count desc]]></select>

只是个参考,还是javabean有用,findresult:

public Map<String, String> findresult(String type, String date) {//返回的date是YYYY或YYYYMMif (type == null) {type = "month";Calendar c = Calendar.getInstance();int y = c.get(Calendar.YEAR);int m = c.get(Calendar.MONTH) + 1;if (m == 1) {m = 12;y -= 1;}if (m < 10) {date = y + "0" + m;} else {date = y + "" + m;}}request.setAttribute("yearfind", date.subSequence(0, 4));if (type.equals("month")) {CharSequence c = date.subSequence(4, 5);if (c.equals("0")) {request.setAttribute("monthfind", date.subSequence(5, 6) + "月");request.setAttribute("monthfind2", date.subSequence(5, 6));} else {request.setAttribute("monthfind", date.subSequence(4, 6) + "月");request.setAttribute("monthfind2", date.subSequence(4, 6));}}Map<String, String> map = new HashMap<String, String>();map.put("date", date);map.put("type", type);return map;}

然后jsp,用到了Bootstrap和jquery,

<style type="text/css">
.center {width: auto;display: table;margin-left: auto;margin-right: auto;
}.width40 {width: 40%;
}
</style>
<table class="table"><tr><td class="width40"><table class="table"><tr><td class="text-center"><h3>查询条件</h3></td></tr><tr><td><div class="radio"><label> <input type="radio" name="datetype" id="dtmonth"value="month" οnclick="choosemonth()" checked="checked">按月查询</label></div><div class="radio"><label> <input type="radio" name="datetype" id="dtyear"value="year" οnclick="chooseyear()"> 按年查询</label></div></td></tr></table><table class="table"><tr><td><div><select class="form-control" id="year"><c:forEach begin="2014" end="${currentYear }"                 <span style="font-family: Arial, Helvetica, sans-serif;">${currentYear }传来的今年年份</span>varStatus="status" var="year"><option value="${currentYear - (year - 2014)}">${currentYear - (year - 2014)}年</option></c:forEach></select></div></td></tr><tr><td><select class="form-control " id="month"><option value="1">1月</option><option value="2">2月</option><option value="3">3月</option><option value="4">4月</option><option value="5">5月</option><option value="6">6月</option><option value="7">7月</option><option value="8">8月</option><option value="9">9月</option><option value="10">10月</option><option value="11">11月</option><option value="12">12月</option></select></td></tr><tr><td><button οnclick="find()" class="btn btn-info">查询</button></td></tr></table></td><td><table class="table table-striped table-bordered"><tr><td colspan="3" class="text-center"><h4><a style="color: blue">${yearfind }年${monthfind }</a>的提出问题排名</h4></td></tr><tr><td class="text-center">排名</td><td class="text-center">姓名</td><td class="text-center">提问数</td></tr><c:forEach items="${StatisticsResult }" var="interrogate"varStatus="stauts"><tr><td class="text-center">${stauts.index+1 }</td><td class="text-center">${interrogate.name}</td><td class="text-center">${interrogate.sumQuestion }</td></tr></c:forEach></table></td></tr></table>

js:

$(function() {//第一次载入是上个月,之后是自己选的$('#year').val('${yearfind }');var m = '${monthfind2 }';if (m != '') {$('#month').val(m);} else {chooseyear();var selects = document.getElementsByName("datetype");selects[1].checked = true;}});function chooseyear() {$('#month').hide();}function choosemonth() {$('#month').show();}function find() {var year = $('#year').val();var month = $('#month').val();if (month.length == 1) {month = "0" + month;}var type = $('input:radio[name=datetype]:checked').val();if (type == "year") {date = year;} else {date = year + month;}window.location.href = '${cp}/statistics/interrogate?date=' + date + '&type=' + type;//下面代码为了说明这个}

说明:最先出现的代码的完整版:

@RequestMapping("interrogate")public String interrogateindex(String type, String date) {Map<String, String> map = findresult(type, date);List<StatisticsInterrogate> list = statisticsService.StatisticsInterrogatelist(map);request.setAttribute("StatisticsResult", list);return "statistics/interrogate";}

完整的可按年份和月份查询数据并显示相关推荐

  1. Python使用matplotlib可视化时间序列季节图、使用季节图可以比较不同年份相同月份的数据差异、或者相同(年/月/周等)的时间序列在同一天的数据差异(Seasonal Plot)

    Python使用matplotlib可视化时间序列季节图.使用季节图可以比较不同年份相同月份的数据差异.或者相同(年/月/周等)的时间序列在同一天的数据差异(Seasonal Plot) 目录

  2. R语言ggplot2可视化:可视化时间序列季节图、使用季节图可以比较不同年份相同月份的数据差异、或者相同(年/月/周等)的时间序列在同一天的数据差异(Seasonal Plot)

    R语言ggplot2可视化:可视化时间序列季节图.使用季节图可以比较不同年份相同月份的数据差异.或者相同(年/月/周等)的时间序列在同一天的数据差异(Seasonal Plot) 目录

  3. 按年份、月份查询SQL语句

    # 第一个是用月份的字段来显示 SELECTDATE_FORMAT( r.assess_time, '%M' ) MONTH,AVG( r.courage ) courage,AVG( r.take ...

  4. sql 如何根据月份查询数据总数_什么是慢查询?如何通过慢查询日志优化?

    日志就跟人们写的日记一样,记录着过往的事情.但是人的日记是主观的(记自己想记的内容),而数据库的日志是客观的,根据记录内容分为以下好几种日志: a.错误日志:记录启动.运行或停止mysqld时出现的问 ...

  5. mysql按时间月份查询数据

    SELECT DATE_FORMAT(call_begin_time, '%Y-%m'), count(1) FROMqy_riskcontrol_prod.phone_statements WHER ...

  6. 【PyQt5】连接 mysql 查询数据 并显示在 tableWidget 表格

    PyQt5 数据库建表 + SQL 语句 Qt designer 制作界面 连接 MySQL 相关知识 查询并获取数据库的数据 运行效果 数据库建表 + SQL 语句 建立一个数据库:test 建立一 ...

  7. mysql 查询数据,显示行号

    转自:Mysql查询显示行号,实现类似Oracle数据库的ROWNUM() - 简书 SELECT( @rownum := @rownum + 1 ) AS rownum,`animal`.* FRO ...

  8. MySQL查询数据案例

    1.单表查询: 1.创建表 CREATE TABLE worker(did INT(11) NOT NULL COMMENT '部门号',uid INT(11) NOT NULL PRIMARY KE ...

  9. MYsql 查询 查询当前月份的数据

    select   date_format( curdate(),'%Y%m') ; 查询当前这周的数据 SELECT name,submittime FROM enterprise WHEREYEAR ...

最新文章

  1. 【图论】有向无环图的拓扑排序
  2. 后台开发经典书籍--大型分布式网站架构设计与实践
  3. Struts1和Struts2的区别和对比(完整版)
  4. Java多线程(五):线程池应该设置多少核心线程数
  5. php-7.2.13的安装,php7.2 安装mcrypt扩展
  6. 【蓝桥杯真题】地宫取宝(搜索-记忆化搜索详解)
  7. 琥珀项目:Java的未来揭晓
  8. html怎么填充颜色渐变,CSS实现不规则图形,填充渐变色
  9. 马后炮之12306抢票工具(四)--抢票Demo,2014年1月9日终结版
  10. oracle笔试题目及答案,Oracle 笔试题目带答案.doc
  11. 1024 程序员节专题论坛来袭,聚焦企业级开源数据库 openGauss
  12. 类与对象、引用传递、封装、构造方法、匿名对象笔记
  13. Chrome浏览器下载zoom录像
  14. 甲乙丙丁四个人去商店每人买了一台计算机,2016国考行测备考:巧用矛盾速解题...
  15. .gitignore详解 copy by 博客园-gt;沙耶
  16. Gentoo虚拟机安装教程
  17. H5音乐播放器我的2.0
  18. 全国计算机考试一的书,《全国计算机等级考试全能教程》—甲虎网一站式图书批发平台...
  19. css3价格斜切_CSS秘密花园:斜切角
  20. 豆瓣首席架构师洪强宁谈Python语言

热门文章

  1. 步步为营 .NET三层架构解析 七、UI的设计(登陆页面、注册页页和添加部门页面)...
  2. 使用protostuff进行序列化
  3. .NET MVC Scripts.Render 上下文不存在问题解决方法
  4. 《Ext JS权威指南》——1.2节JSON概述
  5. ASP.NET Core应用的错误处理[2]:DeveloperExceptionPageMiddleware中间件如何呈现“开发者异常页面”...
  6. Oracle数据库中的dual表
  7. 创建ASM With Oracle 10g
  8. 50matches:更准确的搜索引擎
  9. new失败跟踪函数_关于针对class自定义new操作符失败的函数处理
  10. linux mint php mysql_linux mint 下mysql中文支持问题