zoukankan      html  css  js  c++  java
  • Hibernate使用distinct返回不重复的数据,使用group by 进行分组

    //distinct使用

    public List<String> distinctDutyDate() {
            String hql="select distinct(dutyDate) from DoctorDuty";
            Query query=getSession().createQuery(hql);
            List list= query.list();
            Iterator it= list.iterator();
            List<String> list1=new ArrayList<String>();
            while(it.hasNext()){
                String dutyDate=it.next()+"";
                list1.add(dutyDate);
            }
            return list1;
        }

    //group by使用

    public List<YearMonthDTO> getYearMonthByUserId(Integer userId, String submitType) {
            String hql="select submitYear,submitMonth from TotalBranchSubmit where userId=:userId and submitType=:submitType group by submitYear,submitMonth ";
            Query query = getSession().createQuery(hql)
                    .setParameter("userId",userId)
                    .setParameter("submitType",submitType);
            List list= query.list();
            Iterator it= list.iterator();
            List<YearMonthDTO> list1=new ArrayList<>();
            while(it.hasNext()){
                Object[] res=(Object[]) it.next();
                YearMonthDTO dto=new YearMonthDTO();
                String year=res[0]+"";
                String month=res[1]+"";
                dto.setYear(year);
                dto.setMonth(month);
                list1.add(dto);
            }
            return list1;
        }
  • 相关阅读:
    SQL盲注攻击的简单介绍
    xss编码小结
    XssEncode
    xss payload
    2014年八大信息安全峰会演讲
    xss bypass
    移动APP安全在渗透测试中的应用
    WAF实现扫描器识别
    thinkphp的系统变量
    thinkphp AOP(面向切面编程)钩子和行为
  • 原文地址:https://www.cnblogs.com/pxblog/p/13181267.html
Copyright © 2011-2022 走看看