Criteria使用
public List<Item> findDateByPage(Pagination pagination, long cid){ CriteriaProvider c = CriteriaProvider.getInstance(); //建立关系... c.addAssociations(c.new Association("categories", "categories")); c.addAssociations(c.new Association("systemInfo", "systemInfo")); c.addAssociations(c.new Association("defaultCategory", "defaultCategory"));? ? ? ? ? //Criteria多对多查询... c.addCriterion(Restrictions.or(Restrictions.eq("categories.objectId", cid), Restrictions.eq("defaultCategory.objectId", cid))); c.addCriterion(Restrictions.eq("enable", Boolean.TRUE)); c.addOrder(Order.desc("systemInfo.createDate")); c.setDistinctRootEntity(true);//去重. return itemRepository.findFrontByPage(pagination, c); }?