- 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)】:
[java] view plain copy
- 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();】:
[java] view plain copy
- 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);
- }
-
hibernate 查询match mode的四种模式
Hibernate 查询MatchMode的四种模式
MatchMode.START:字符串在最前面的位置.相当于"like ‘key%‘"
MatchMode.END:字符串在最后面的位置.相当于"like ‘%key‘"
MatchMode.ANYWHERE:字符串在中间匹配.相当于"like ‘%key%‘"
MatchMode.EXACT:字符串精确匹配.相当于"like ‘key‘"
时间: 2024-10-07 03:23:51