zoukankan      html  css  js  c++  java
  • Hibernate 查询

    1、or 查询

            //两个条件
            criteria.add(Restrictions.or(Restrictions.ilike("name", keyword, MatchMode.ANYWHERE), 
                    Restrictions.ilike("phone", keyword, MatchMode.ANYWHERE)));
            
            //多个or条件
            criteria.add(Restrictions.disjunction()
                    .add(Restrictions.ilike("name", keyword, MatchMode.ANYWHERE))
                    .add(Restrictions.ilike("phone", keyword, MatchMode.ANYWHERE)));

    2、统计查询

            criteria.createAlias("member", "member", CriteriaSpecification.INNER_JOIN);
            ProjectionList projectionList = Projections.projectionList();
            projectionList.add(Projections.property("member.id").as("id"));
            projectionList.add(Projections.property("member.loginName").as("loginName"));
            projectionList.add(Projections.property("name"));
            projectionList.add(Projections.property("phone"));
            projectionList.add(Projections.sum("money"));
            projectionList.add(Projections.sum("remainMoney"));
            //sqlProjection的使用
            projectionList.add(Projections.sqlProjection("sum(case end_time < '"+dateTime+"' when 1 then remain_money else 0 end) as expired_money", new String[]{"expired_money"}, new Type[]{ new DoubleType()}));
            projectionList.add(Projections.property("redEnvelope.id"));
            projectionList.add(Projections.groupProperty("member.loginName"));
            criteria.setProjection(projectionList);
  • 相关阅读:
    mcstructs使用CMake生成Makefile文件
    打印man手册为pdf文件
    ubuntu安装wine之后进不了系统
    如何知道自己梦呓的内容
    Opencv step by step
    Opencv step by step
    树莓派实现只有一个按键的播放器
    virtualbox 打不开ubuntu解决
    wifi使用的一些误区
    Opencv step by step
  • 原文地址:https://www.cnblogs.com/rubekid/p/4255823.html
Copyright © 2011-2022 走看看