- public Page getCoordByPage(Page queryHandler, TCoordinate conditions) {
- DetachedCriteria dc = DetachedCriteria.forClass(TCoordinate.class);
- if (conditions.getTAxis() != null) {
- dc.add(Restrictions.eq("TAxis", conditions.getTAxis()));
- }
- if(conditions.getCoordinateName()!=null){
- dc.add(Restrictions.like("coordinateName", conditions.getCoordinateName(),MatchMode.ANYWHERE).ignoreCase());
- }
- if(conditions.getParentCoordinate().getId()!=null){
- dc.add(Restrictions.eq("parentCoordinate.id", conditions.getParentCoordinate().getId()));
- }
- dc.addOrder(Order.desc("addDate"));
- Page page = this.coordinateDao.getPageByCriteria(queryHandler, dc);
- return page;
- }
两个条件之间or的用法【Restrictions.or(lhs, rhs)】:
- dc.add(Restrictions.or(Restrictions.like("country", comm.getCountry(),MatchMode.ANYWHERE).ignoreCase(),
- Restrictions.like("pinyin", comm.getCountry(),MatchMode.ANYWHERE).ignoreCase()));
超过两个,比如三个条件之间的or【Disjunction disjunction = Restrictions.disjunction();】:
- if(!ValidateUtils.isEmpty(comm.getCountry())){
- Disjunction disjunction = Restrictions.disjunction();
- disjunction.add(Restrictions.like("country", comm.getCountry(),MatchMode.ANYWHERE).ignoreCase());
- disjunction.add(Restrictions.like("pinyin", comm.getCountry(),MatchMode.ANYWHERE).ignoreCase());
- disjunction.add(Restrictions.like("jianpin", comm.getCountry(),MatchMode.ANYWHERE).ignoreCase());
- dc.add(disjunction);
- }
瞬即涨姿势!