企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## QBC查询(Criteria方式) 特点:完全面向对象. ## 全查 ~~~ Criteria criteria = session.createCriteria(Customer.class); List<Customer> list = criteria.list(); for (Customer c : list) { System.out.println(c); } ~~~ ## 条件查 条件可以去网上看, Restrictions.条件 ~~~ Criteria criteria = session.createCriteria(Customer.class); criteria.add(Restrictions.like("name", "%j%")); List<Customer> list = criteria.list(); ~~~ ## 分页查 ~~~ Criteria criteria = session.createCriteria(Customer.class); criteria.setFirstResult(2); criteria.setFirstResult(2); List<Customer> list = criteria.list(); ~~~ ## 排序查 ~~~ Criteria criteria = session.createCriteria(Customer.class); criteria.addOrder(Order.desc("name")); List<Customer> list = criteria.list(); ~~~ ## 聚合查 ~~~ Criteria criteria = session.createCriteria(Customer.class); //下面两条语句是一致的 criteria.setProjection(Projections.count("id")); // criteria.setProjection(Projections.rowCount()); Object o = criteria.uniqueResult(); System.out.println(o); ~~~