Criteria Query常用的查询限制方法
来源:互联网 发布:恋爱 知乎 编辑:程序博客网 时间:2024/05/21 11:22
Restrictions.like(属性名, 查询条件的值, 匹配方式):
Restrictions.in(属性名, 查询条件的值, 匹配方式):
Restrictions.eq(属性名, 查询条件的值, 匹配方式):
CriteriaQuery常用的查询限制方法
Restrictions.eq() equal,=
Restrictions.allEq() 参数为Map对象,使用key/value进行多个等于的对比,相当于多个Restrictions.eq()的效果
Restrictions.gt() greater-than, >
Restrictions.lt() less-than, <
Restrictions.le() less-equal, <=
Restrictions.between() 对应SQL的between子句
Restrictions.like() 对应SQL的like子句
Restrictions.in() 对应SQL的in子句
Restrictions.and() and关系
Restrictions.or() or关系
Restrictions.isNull() 判断属性是否为空,为空返回true,否则返回false
Restrictions.isNotNull() 与Restrictions.isNull()相反
Order.asc() 根据传入的字段进行升序排序
Order.desc() 根据传入的字段进行降序排序
MatchMode.EXACT 字符串精确匹配,相当于“like 'value'”
MatchMode.ANYWHERE 字符串在中间位置,相当于“like '%value%'”
MatchMode.START 字符串在最前面的位置,相当于“like 'value%'”
MatchMode.END 字符串在最后面的位置,相当于“like '%value'”
public List search(TblFwxx condition) { Session session = this.getSession();Criteria c = session.createCriteria(TblFwxx.class);if (null != condition) {if (condition.getTitle() != null && !condition.getTitle().equals("")) {c.add(Restrictions.like("title", condition.getTitle(), MatchMode.ANYWHERE)); } } c.addOrder(Order.asc("fwid"));return c.list();}
-------------------------------------------------------------------------------------
例1:
表中的数据为:
userid name username password age
------------------------------------------------
</pre> <wbr> 2 <wbr> <wbr> <wbr>李四 <wbr> <wbr> li4 <wbr> <wbr> <wbr> <wbr> <wbr> li4 <wbr> <wbr> <wbr> <wbr> 21 <wbr> 3 <wbr> <wbr> <wbr> your <wbr> <wbr>test <wbr> <wbr> <wbr> <wbr> <wbr>test <wbr> <wbr> <wbr> <wbr> 30<p></p><p></p><p> </p><p></p><p>------------------------------------------------------------------------------------</p><p></p><p>例2:</p><p></p><p> <wbr></wbr></p><p><pre class="java" name="code">private Session session;public List criteria(SalChance salChance) { List result = null; try { session = super.getSession(); Criteria cri = session.createCriteria(SalChance.class); if(salChance.getChcCustName()!=null&&salChance.getChcCustName()!=""){ cri.add(Restrictions.like("chcCustName", salChance.getChcCustName(),MatchMode.ANYWHERE)); } if(salChance.getChcTitle()!=null&&salChance.getChcTitle()!=""){ cri.add(Restrictions.like("chcTitle", salChance.getChcTitle(),MatchMode.ANYWHERE)); } if(salChance.getChcLinkman()!=null&&salChance.getChcLinkman()!=""){ cri.add(Restrictions.like("chcLinkman", salChance.getChcLinkman(),MatchMode.ANYWHERE)); } if(salChance.getChcStatus()!=null&&salChance.getChcStatus()!=""){ //System.out.println("状态为:"+salChance.getChcStatus()); if(salChance.getChcStatus()=="all"){ cri.add(Restrictions.in("chcStatus", new Object[]{"2","3","4"})); }else{ cri.add(Restrictions.eq("chcStatus", salChance.getChcStatus())); } } result=cri.list(); } catch (Exception e) { e.printStackTrace(); }finally { session.close(); } return result;
- Criteria Query常用的查询限制方法
- Query By Criteria的限制条件写法
- Hibernate的 SessionFactory,Configuration,Query ,Criteria接口简介,及Query的查询方法
- Hibernate 的查询语言 Criteria 和Query
- hibernate中的Query查询和criteria查询的区别
- Hibernate中Criteria查询常用方法
- Hibernate条件查询(Criteria Query)
- Hibernate条件查询(Criteria Query)
- Hibernate条件查询(Criteria Query)
- Hibernate条件查询(Criteria Query)
- Hibernate条件查询(Criteria Query)
- Hibernate-Criteria Query模糊查询
- NHibernate条件查询(Criteria Query)
- Hibernate 之 Criteria 、 Query 查询
- hibernate的Criteria Query
- Hibernate的Criteria Query
- Hibernate 的Criteria Query
- 第十一章 Hibernate的查询 Query by Criteria(QBC)
- DedeCMS借助function扩展实现特殊调用
- No result defined for action and result input
- iOS开发 UIWebView获取点击图片
- sqllite 之根据时间区间筛选数据
- IE8报错:Unable to modify the parent container element before the child element is closed
- Criteria Query常用的查询限制方法
- JavaScript权威指南_47_第6章_对象_6.10-对象方法
- python快速学习笔记
- windows下python protobuf 安装
- 铁道部新客票系统的设计。
- 如何用多个字符串来切分字符串
- webview 属性以及整体介绍
- Android -animation-Property Animation
- Netty SSL开发