方法
说明
Restrictions.eq
Restrictions.allEq
利用Map来进行多个等于的限制
Restrictions.gt
Restrictions.ge
>=
Restrictions.lt
Restrictions.le
<=
Restrictions.between
BETWEEN
Restrictions.like
LIKE
Restrictions.in
in
Restrictions.and
and
Restrictions.or
or
Restrictions.sqlRestriction
SQL限定查
 
 

MatchMode类包含的各个静态常量实例

匹配模式

举例

MatchMode.START

Expression.like(“name”,”y”, MatchMode.START)

姓名以y开头

MatchMode.END

Expression.like(“name”,”y”, MatchMode. END)

姓名以y结尾

MatchMode.ANYWHERE

Expression.like(“name”,”y”, MatchMode. ANYWHERE)

姓名中包含y

MatchMode.EXACT

Expression.like(“name”,”y”, MatchMode. EXACT)

精确匹配,姓名必须为y

 


示例:

01 DetachedCriteria detachedCrit = DetachedCriteria.forClass(User.class);
02 detachedCrit.addOrder(Order.asc("uname"));  //按照姓名排序
03  
04 if (user!=null && user.getUname()!=null&& user.getUname().trim().length()>0//姓名查询条件
05     detachedCrit.add(Restrictions.like("uname", user.getUname().trim(), MatchMode.ANYWHERE));
06 if (user!=null && user.getUloginId()!=null && user.getUloginId().trim().length()>0)  //身份证号查询条件
07     detachedCrit.add(Restrictions.like("uloginId", user.getUloginId().trim(), MatchMode.ANYWHERE));
08 if(user!=null && user.getType()!=null && user.getType()!=0) {
09     detachedCrit.add(Restrictions.eq("type", user.getType()));
10 }