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(尊重原创)
作者:ruicky
出处:http://www.cnblogs.com/ruicky/
欢迎任何形式的转载,未经作者同意,请保留此段声明!