hibernate的条件查询

static List query(String name){

    Session session = null;

   

     try{

         s = HibernateUtil.getSession();

         Criteria c = session.createCriteria(User.class);

c.add(Restrictions.eq("name",name));//约束条件

c.setFirstResult(0);//分页

c.setMaxResults(10);//分页

Useruser=(User)c.uniqueResult();

         List list = c.list();

     }finally{

             if(s!=null)

             s.close();

     }

     return list

}

相关推荐