欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Restrictions用法

程序员文章站 2022-03-11 21:40:07
...
例子一:
    
public List<Goods> ranking(String path, TimeUnit timeUnit, String time, int size) {
List<Criterion> criterions = new ArrayList<Criterion>();
criterions.add(Restrictions.sqlRestriction("{alias}.sn in (SELECT SN FROM MALL_GOODS WHERE MARKETABLE = ?)", true, BooleanType.INSTANCE));
criterions.add(Restrictions.eq("type", Sales.Type.goods));
criterions.add(Restrictions.like("path", path + "%"));
criterions.add(Restrictions.eq("timeUnit", timeUnit));
criterions.add(Restrictions.eq("time", time));
List<Sales> goodsSales = salesService.sellingRanking(criterions.toArray(new Criterion[criterions.size()]), 0, size);
if (goodsSales.isEmpty()) {
return Collections.EMPTY_LIST;
}
List<Goods> list = this.goodsDao.find(Restrictions.in("sn", ObjectUtil.toFieldArray(goodsSales, "sn", String.class)));
List<Goods> goods = new ArrayList<Goods>();
for (Sales sales : goodsSales) {
goods.add(ObjectUtil.find(list, "sn", sales.getSn()));
}
return goods;
}


例子二:

Restrictions.sql("lower({alias}.name) like lower(?)", "Fritz%", Hibernate.STRING) )
Restrictions.sqlRestriction(" {alias}.properties like ? ", "%" + value + "%", StringType.INSTANCE)




例子三:


this.goodsCategoryDao.find(new Criterion[]{Restrictions.eq("delflag",Delflag.N)}, "layer,sort", "asc,asc");


例子四:

public Pager<Depot> totalfindPager(Pager<Depot> pager,List<PropertyFilter> filters) {
Criterion[] criterions = buildPropertyFilterCriterions(filters);
Criteria criteria = this.createCriteria(criterions);

ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.groupProperty("sn"), "sn");
projectionList.add(Projections.sum("badCommodityQuantity"),"totalBadCommodityQuantity");
projectionList.add(Projections.sum("goodCommodityQuantity"),"totalGoodCommodityQuantity");

criteria.setProjection(projectionList);
criteria.setResultTransformer(new AliasToBeanResultTransformer(Depot.class));

pager.reset(countCriteriaResult(criteria));
setPageParameter(criteria, pager);
pager.reset(criteria.list());

return pager;
}