方法 |
说明 |
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" )); //按照姓名排序 |
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())); |
|
|
随笔:0
文章:40
评论:4
引用:0
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
27 | 28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|
留言簿
文章档案
搜索
最新评论
|
|