- 浏览: 642565 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
HkEndless:
不好意思,请问这确定是回调机制吗。你的例子中只是将接口的实现类 ...
Spring CallBack回调机制介绍 -
hanmiao:
写的真乱啊,完全不知所云...
Java如何调用可执行文件和批处理命令 -
junia_1:
junia_1 写道 shock: ...
为什么要使用EJB -
junia_1:
shock:
为什么要使用EJB -
coollifer:
不错
SQL Server数据导入到Oracle中的方法
方法 |
说明 |
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限定查询 |
QBC常用限定方法
Restrictions .eq --> equal,等于.
Restrictions .allEq --> 参数为Map对象,使用key/value进行多个等于的比对,相当于多个Restrictions .eq 的效果
Restrictions .gt --> great-than > 大于
Restrictions .ge --> great-equal >= 大于等于
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
Restrictions .isNotNull --> 与isNull相反
Restrictions .sqlRestriction --> SQL限定的查询
Order.asc --> 根据传入的字段进行升序排序
Order.desc --> 根据传入的字段进行降序排序
MatchMode.EXACT --> 字符串精确匹配.相当于"like 'value'"
MatchMode.ANYWHERE --> 字符串在中间匹配.相当于"like '%value%'"
MatchMode.START --> 字符串在最前面的位置.相当于"like 'value%'"
MatchMode.END --> 字符串在最后面的位置.相当于"like '%value'"
例子
查询年龄在20-30岁之间的所有学生对象
List list = session.createCriteria(Student.class)
.add(Restrictions
.between("age",new Integer(20),new Integer(30)).list();
查询学生姓名在AAA,BBB,CCC之间的学生对象
String[] names = {"AAA","BBB","CCC"};
List list = session.createCriteria(Student.class)
.add(Restrictions
.in("name",names)).list();
查询年龄为空的学生对象
List list = session.createCriteria(Student.class)
.add(Restrictions
.isNull("age")).list();
查询年龄等于20或者年龄为空的学生对象
List list = session.createCriteria(Student.class)
.add(Restrictions
.or(Restrictions
.eq("age",new Integer(20)),
Restrictions
.isNull("age")).list();
--------------------------------------------------------------------
使用QBC实现动态查询
public List findStudents(String name,int age){
Criteria criteria = session.createCriteria(Student.class);
if(name != null){
criteria.add(Restrictions
.liek("name",name,MatchMode.ANYWHERE));
}
if(age != 0){
criteria.add(Restrictions
.eq("age",new Integer(age)));
}
criteria.addOrder(Order.asc("name"));//根据名字升序排列
return criteria.list();
}
-----------------------------------------------------------------------------------
今天用了写hibernate
高级查询时用了Restrictions
(当然Expression也是可以以的)这个类.感觉不错.
下面的代码写的不易读.其实核心就是一句
Restrictions
.or(Restrictions
.like(),Restrictions
.or(Restrictions
.like,........))
里面的or可以无限加的.还是比较好用
Session session = getHibernateTemplate().getSessionFactory()
.openSession();
Criteria criteria = session.createCriteria(Film.class);
List<Film> list = criteria.add(
Restrictions
.or(Restrictions
.like("description", key,MatchMode.ANYWHERE),
Restrictions
.or(Restrictions
.like("name", key,MatchMode.ANYWHERE),
Restrictions
.or( Restrictions
.like("direct", key,MatchMode.ANYWHERE),
Restrictions
.or(Restrictions
.like("mainplay",key,MatchMode.ANYWHERE),
Restrictions
.like("filearea", key,MatchMode.ANYWHERE)))))).list();
session.close();
return list;
发表评论
-
URLClassLoader
2012-05-27 19:45 959This example shows how a serv ... -
MyClassLoader 自定义类加载器
2012-05-27 19:38 1468package demo; import java. ... -
Deal with big-endian and little-endian order
2011-12-25 19:17 1064Java virtual machine always use ... -
修改eclipse的背景色
2011-11-12 19:23 1078eclipse 操作界面默认颜色为白色。对于我们长期 ... -
hibernate3 大批量更新/删除数据 (update/delete)
2011-11-10 12:15 1339Hibernate3.0 采用新的基 ... -
多线程管道流输入输出模式
2011-11-07 07:23 1059import java.io.* ; class Send ... -
Java计数单字节双字节字符个数的例子
2011-10-26 14:29 1270/* 计数单双字符的个数并存储在Map对象中 ... -
常用内存数据库3
2011-10-24 00:24 14514.1.2 哪些场合适合使用其他的关系型数据库管 ... -
hibernate lazy(延迟加载)
2011-10-12 02:20 882hibernate lazy策略可以使用在: * < ... -
一些关于Hibernate延迟加载的误区
2011-09-12 23:13 843首先是第一个误区:延迟加载只能作用于关联实体 看到这个是 ... -
java字节码规则
2011-09-05 13:56 1218栈和局部变量操作 将常量压入栈的指令 aconst_nul ... -
Tomcat中限制ip访问
2011-08-23 21:40 1216Tomcat中限制ip访问是非常简单的,只需要编辑server ... -
一个Java程序员应该掌握的10项技能
2011-08-22 10:27 5851、语法:必须比较熟 ... -
2011 年 8 月 Java 开发人员新闻快讯
2011-08-18 18:59 797Java SE 7 发布了! 经过世界各地 Ja ... -
BlockingQueue
2011-08-13 09:59 683import java.util.concurrent.Arr ... -
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling
2011-08-12 19:17 1207Hi I am facing a problem wit ... -
eclipse中java项目转换为web项目
2011-07-27 18:29 867经常在eclipse中导入web项目时,出现转不了项目类型 ... -
Oracle官方Weblogic插件安装
2011-07-20 22:00 2833Installing Oracle Enterprise Pa ... -
Criteria Condition: Match Mode End
2011-07-02 11:05 945//////////////////////////// ... -
Criteria: Group By Criteria
2011-07-02 11:03 1251/////////////////////////////// ...
相关推荐
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain ...
。。。
。。。
Contents 1 Legal notice 11 2 Introduction 13 2.1 Background . . . . . . ....2.1.1 Compilers ....2.2 This work ....2.2.3 Restrictions in this document . . . . . . . . . . . . . . . . 14 3 The t
jar包:项目中除了使用了struts2,hibernate3.0和spring1.8以外(用spring2.0的包也可以.不能低于1.8的包.)还是用了junit,ajax,第三方的table组件.等等.所以需要下载相对应的包. 为了上传jar.我专门申请了一个网盘.所有...
Restrictions of the Demo mode ..................................................................................... 2 2. Capturing photos .................................................................
Table of Contents Summary of GDB . . . . . . . . ....Free software ....Contributors to GDB ....A Sample GDB Session ....Loading the Executable ....Setting Display width....Setting Breakpoints ....Running the executable ...
4.1.1 MSD transfer in push mode ......................................................................................................... 25 4.1.2 MSD update in TX idling mode ...........................
Enabling taint mode.........................................................................................................18 Taint and the environment ..................................................
Adobe Acrobat Reader) without any restrictions -- i.e. with edit/copy/print functions enabled. All versions of Adobe Acrobat (including 7.x, which features 128-bit encryption) are supported.
Working in Advanced user mode ........................................................................ 70 Setting values for attributes and variables.....................................................
Oracle_start_with_connect_by_prior_用法[文].pdf
Adobe Acrobat Reader) without any restrictions -- i.e. with edit/copy/print/annotate functions enabled. Please note that APDFPR doesn't work with documents which have user-level passwords (preventing...
Hibernate Object/Grid Mapper (OGM) aims at providing Java Persistence (JPA) support for NoSQL solutions. It reuses Hibernate Core's engine but persists entities into a NoSQL data store instead of a ...
2.3.8 Match the Tool to the Bug . . . . . . . . . 12 2.3.9 One Change at a Time . . . . . . . . . 12 2.3.10 Keep an Audit Trail . . . . . . . . 12 2.3.11 Get a Fresh View . . . . . . . . . . . 13 ...
Dynamic IP Restrictions: 保護 IIS 網站的流量守門員 iis 插件
Adobe Acrobat Reader) without any restrictions -- i.e. with edit/copy/print functions enabled. All versions of Adobe Acrobat (including 7.x, which features 128-bit encryption) are supported.
PDF文档有时不能复制,粘贴,可能是因为屏蔽了复制功能,A-PDF Restrictions Remover可以解除这种屏蔽
Resource Naming Restrictions ......................................................................................................... 2-2 Editing Resources...............................................