• Expression查询语法


    A:Expression查询语法

    1:Expression.eq: 对应sql(fidld=value):Expression.eq("name","zhengjigang")

    2:Expression.allEq:参数为一个Map对象。相当于多个Expression.eq关系的叠加

    3:Expression.gt:对应sql(field>value)

    4:Expression.ge:对应sql(field>=value)

    5:Expression.lt:对应sql(field<value)

    6:Expression.le:对应sql(field<=value)

    7:Expression.between:对应sql中的between表达式:Expression.between("age",new Integer(13),new Integer(15))

    8:Expression.like:对应sql(field like value)

    9:Expression.in:对应sql(field in value)

    10:Expression.eqProperty:对应pojo属性的sql(field=field):Expression.eqProperty("Tuser.groupId","Tgroup.id")

    11:Expression.gtProperty:对应的sql(field>field)

    12:Expression.geProperty:对应的sql(field>=field)

    13:Expression.ltProperty:对应的sql(field<field)

    14:Expression.leProperty:对应的sql(field<=field)

    15:Expression.and:and关系组合:Expression.and(Expression.eq("name","zhengjigang"),Expression.eq("job","软件工程师"))

    16:Expression.or:and关系组合:Expression.or(Expression.eq("name","zhengjigang"),Expression.eq("job","软件工程师"))

    17:Expression.sql:提供原生sql语法的支持:Expression.sql("lower({demo}.name) like lower(?)","zhengjigang%",Hibernate.String)

    B:Criteria的高级查询

    1: 限定返回的记录条数:Criteria criteria=session.createCriteria(Tuser.class);          criteria.setFirstResult(100);//开始的记录的索引          criteria.setMaxResults(20)//取得最大民录数

    2:对记录进行排序:Criteria criteria=session.createCriteria(Tuser.class);     criteria.add(Expression.eq("name","zhengjigang"));     criteria.addOrder(Order.asc("name")); //对name字段进行升序排序

    收集过来方便自己以后自己使用  原文链接http://sunny-java-163-com.iteye.com/blog/785169(尊重原创)

  • 相关阅读:
    Java面试:用set集合的时候,重写过hashcode()和equal()方法吗?有什么作用?
    Bootstrap起步
    Java NIO
    Dobbo和SpringCloud区别
    Java虚拟机类加载机制和双亲委派模型
    继承和组合的特点和区别
    LinkedList和ArrayList底层原理
    聚集索引和非聚集索引
    Stream和迭代器的区别
    悲观锁和乐观锁
  • 原文地址:https://www.cnblogs.com/ruicky/p/2592981.html
Copyright © 2020-2023  润新知