DetachedCriteria 實現多表關聯,檢索條件
阿新 • • 發佈:2019-02-04
DetachedCriteria queryCriteria = DetachedCriteria.forClass(Rsvmain.class); if (ObjectUtils.isNotEmpty(query.getUnitinfoName())) { DetachedCriteria unitinfo = DetachedCriteria.forClass(Unitinfo.class); unitinfo.add(Restrictions.like("unitnm", "%" + query.getUnitinfoName() + "%")); unitinfo.setProjection(Property.forName("id")); queryCriteria.add(Property.forName("unitinfoId").in(unitinfo)); } if (ObjectUtils.isNotEmpty(query.getMemberName())) { DetachedCriteria member = DetachedCriteria.forClass(Member.class); member.add(Restrictions.disjunction() .add(Restrictions.like("lastnm", "%" + query.getMemberName() + "%")) .add(Restrictions.like("firstnm", "%" + query.getMemberName() + "%")) .add(Restrictions.like("altnm", "%" + query.getMemberName() + "%"))); member.setProjection(Property.forName("id")); queryCriteria.add(Property.forName("memberId").in(member)); } if (ObjectUtils.isNotEmpty(query.getStartdt()) || ObjectUtils.isNotEmpty(query.getEnddt())) { DetachedCriteria rsvdtl = DetachedCriteria.forClass(Rsvdtl.class); if (ObjectUtils.isNotEmpty(query.getStartdt())) { rsvdtl.add(Restrictions.ge("cidt", query.getStartdt())); } if (ObjectUtils.isNotEmpty(query.getEnddt())) { rsvdtl.add(Restrictions.le("codt", query.getEnddt())); } rsvdtl.setProjection(Property.forName("rsvmainId")); queryCriteria.add(Property.forName("id").in(rsvdtl)); }