Hibernate的学习总结(Criteria对象)

    技术2024-10-24  21

    Criteria对象的获取:

    Criteria criteria = session.createCriteria(Person.class); // Person为POJO类

    criteria.add(Expression.eq("name","han")); // name为Person类的属性 相当于 name = 'han'

    List list = criteria.list();

     

    Expression.eq   [=]

    Expression.gt    [>]

    Expression.ge   [>=]

    Expression.lt     [<]

    Expression.ie    [<=]

    Expression.between("age",new Integer(13),new Integer(14))   [between.....and.......]

    Expression.like("name","%han%")  [like]

     

    Set<Integer> conds = new TreeSet<Integer>();conds.add(new Integer(1));conds.add(new Integer(2));

    cri.add(Expression.in("id", conds));  [IN]   相当于id IS IN(1,2)List all = cri.list();

     

    Expression.and(Expression.eq("name","han"),Expression.eq("name","han"));  [AND]  

    Expression.or(Expression.eq("name","han"),Expression.eq("name","han"));     [OR]

     

    最新回复(0)