通过对象的非主键属性查询,返回list集合。代码:
测试代码:
/**
* 按对象属性查询
*/
this.productDao.findBypropertiesIn(new CriteriaCallBackEntity<Product>(){
public void setCriteria(Criteria criteria){
Product product = new Product();
product.setVendor("v.1");
product.setPrice(10);
Example example = Example.create(product).enableLike(MatchMode.ANYWHERE).excludeProperty("price");
criteria.add(example);
}
});
public interface CriteriaCallBackEntity<T> {
public void setCriteria(Criteria criteria);
}
public void findBypropertiesIn(final CriteriaCallBackEntity<T> criteriaCallBackEntity)
{
List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(type);
criteriaCallBackEntity.setCriteria(criteria);
List list = criteria.list();
return list;
}
});
System.out.println(list.size()+">>>>>>>>>>>>>..");
}