zoukankan      html  css  js  c++  java
  • 分类统计的controller和service

    SpringMVC框架下的 部分代码:

    Controller控制器:

    @Resource
    ReviewTitleService reviewTitleService;//调用ReviewTitleService 类时,先定义一个对象

    Gson gson = new Gson();//调用Gson 时,先定义一个对象

    /**
    * 获得职称评审通过率
    * @param request
    * @param department
    * @param year
    * @return
    */
    @ResponseBody
    @RequestMapping(value = "getRate", produces = "application/json; charset=utf-8")
    public String getRate(HttpServletRequest request,
    @RequestParam(required = false) String department,
    @RequestParam(required = false) String year){
    return gson.toJson(reviewTitleService.getRate(department, year));

    }

    Service接口:

    /**
    * 获得评审表通过率
    * @param department
    * @param year
    */
    public List<Map<String, Object>> getRate(String department, String year){
    try {
    String sql = "SELECT s.FIRSTDEPARTMENT as department, t.YEAR as year, "
    + "SUM(CASE WHEN t.STATE>=50 AND t.STATE<60 THEN 1 ELSE 0 END) as reportNmuber, "
    + "SUM(CASE WHEN t.STATE>=60 THEN 1 ELSE 0 END) as throughNumber, "
    + "SUM(CASE WHEN t.STATE>=60 THEN 1 ELSE 0 END)/SUM(CASE WHEN t.STATE>=50 THEN 1 ELSE 0 END) as rate "
    + "FROM rt_review_title t "
    + "LEFT JOIN staff s ON s.CODE=t.CODE where 1=1 ";
    if (year != null && !"".equals(year)) {
    sql += "and t.year = '" + year + "' ";
    }
    if (department != null && !"".equals(department)) {
    sql += "and s.FIRSTDEPARTMENT = '" + department + "' ";
    }
    sql += "GROUP BY t.YEAR,s.FIRSTDEPARTMENT";
    System.out.println(sql);
    List<Map<String, Object>> result = hibernateDao.findSql(sql);
    System.out.println(result);
    return result;
    } catch (Exception e) {
    e.printStackTrace();
    return null;
    }

    }

  • 相关阅读:
    TCP IP基础知识的复习
    Design Pattern: Singleton 模式
    解决Win7下安装VS2010不显示序列号框的两种方法
    字典树(Trie tree)
    在VS如何查看汇编代码
    使用模板实现编译期间多态
    一段c++代码小例子
    C++ 虚函数表解析
    C++问题:if( input.rdstate() & std::ios::failbit )
    Design Pattern: Adapter 模式 Class Adapter
  • 原文地址:https://www.cnblogs.com/sbclmy/p/9145358.html
Copyright © 2011-2022 走看看