Criteria接口

Criteria接口和Query接口类似,它允许创建并执行面向对象方式的查询,例如以下代码:

public static void main(String[] args) {
		Configuration configuration=new Configuration().configure();
		SessionFactory sessionFactory=configuration.buildSessionFactory();
		Session session=sessionFactory.openSession();
		Transaction transaction=session.beginTransaction();
		Criteria criteria=session.createCriteria(News.class);
		Criterion criterion=Restrictions.eq("id", new Integer(1));
		criteria.add(criterion);
		List<News> newss=criteria.list();
		transaction.commit();
		session.close();
		for(News news:newss){
			System.out.println(news.getTitle()+"======"+news.getContent());
		}	
	}

 

你可能感兴趣的:(Criteria)