- 浏览: 21252 次
- 性别:
- 来自: 北京
最新评论
ibatis:
ibatis中dao中的方法在使用sqlMapClient时只能传递一个参数,若是多个要转换,最好用Map param=new HashMap();
在sqlMapClient调用查询方法时,一般返回结果为单行的要使用queryForObject,
返回结果为多行时使用queryForList
1、若参数为基本类型,怎##中可任意命名
<delete id="deleteDept" parameterClass="int">
delete from dept where deptno=#aaa#;
</delete>
2、若返回值是带有类的list等,则返回值类型还要配置为类
<select id="findDepts" resultClass="com.puckasoft.po.Dept">
select * from dept
</select>
3、若需要用模糊查询时则#要换成'$
<select id="findEmpsByEname" parameterClass="java.lang.String"
resultClass="com.puckasoft.po.Emp">
select * from emp where ename like '$abc$'
</select>
4、带多个参数:
public List<Emp> findEmps(Date beginDate, Date endDate, Float hisal,
Float losal) {
Map params=new HashMap();
params.put("beginDate", beginDate);
params.put("endDate", endDate);
params.put("hisal", hisal);
params.put("losal", losal);
try {
return sqlMapClient.queryForList("findEmps", params);
} catch (SQLException e) {
throw new DaoException();
}
}
<select id="findEmps" parameterClass="hashMap" resultClass="com.puckasoft.po.Emp">
select * from emp where hiredate between #beginDate# and #endDate# and sal between #losal# and #hisal#
</select>
5、ibatis会自动识别数据库,根据不同的数据库进行不同的分页,因此不需要自己写,对于分页只需select * from **即可
public List<Emp> findEmpsByPage(int firstResult, int maxResults) {
try {
return sqlMapClient.queryForList("findEmpsByPage", firstResult, maxResults);
} catch (SQLException e) {
throw new DaoException();
}
}
<select id="findEmpsByPage" resultClass="com.puckasoft.po.Emp">
select * from emp
</select>
6、返回结果为map类型的,配置时也要写为hashMap:
public List<Map> findHisalByDept() {
try {
return sqlMapClient.queryForList("findHisalByDept");
} catch (SQLException e) {
throw new DaoException();
}
}
<select id="findHisalByDept" resultClass="hashMap">
select deptno,max(sal) from emp group by deptno order by max(sal) desc
</select>
ibatis+spring:
1.拷贝工程
2.加入 sping db pool的jar
3.加入applicationContext.xml
4.删除sqlMapConfig.xml 的tx标签
5.编写applicationContext.xml
6.去掉单例,去掉sqlMapClient的取值,加入setter,getter
7.测试
ibatis中dao中的方法在使用sqlMapClient时只能传递一个参数,若是多个要转换,最好用Map param=new HashMap();
在sqlMapClient调用查询方法时,一般返回结果为单行的要使用queryForObject,
返回结果为多行时使用queryForList
1、若参数为基本类型,怎##中可任意命名
<delete id="deleteDept" parameterClass="int">
delete from dept where deptno=#aaa#;
</delete>
2、若返回值是带有类的list等,则返回值类型还要配置为类
<select id="findDepts" resultClass="com.puckasoft.po.Dept">
select * from dept
</select>
3、若需要用模糊查询时则#要换成'$
<select id="findEmpsByEname" parameterClass="java.lang.String"
resultClass="com.puckasoft.po.Emp">
select * from emp where ename like '$abc$'
</select>
4、带多个参数:
public List<Emp> findEmps(Date beginDate, Date endDate, Float hisal,
Float losal) {
Map params=new HashMap();
params.put("beginDate", beginDate);
params.put("endDate", endDate);
params.put("hisal", hisal);
params.put("losal", losal);
try {
return sqlMapClient.queryForList("findEmps", params);
} catch (SQLException e) {
throw new DaoException();
}
}
<select id="findEmps" parameterClass="hashMap" resultClass="com.puckasoft.po.Emp">
select * from emp where hiredate between #beginDate# and #endDate# and sal between #losal# and #hisal#
</select>
5、ibatis会自动识别数据库,根据不同的数据库进行不同的分页,因此不需要自己写,对于分页只需select * from **即可
public List<Emp> findEmpsByPage(int firstResult, int maxResults) {
try {
return sqlMapClient.queryForList("findEmpsByPage", firstResult, maxResults);
} catch (SQLException e) {
throw new DaoException();
}
}
<select id="findEmpsByPage" resultClass="com.puckasoft.po.Emp">
select * from emp
</select>
6、返回结果为map类型的,配置时也要写为hashMap:
public List<Map> findHisalByDept() {
try {
return sqlMapClient.queryForList("findHisalByDept");
} catch (SQLException e) {
throw new DaoException();
}
}
<select id="findHisalByDept" resultClass="hashMap">
select deptno,max(sal) from emp group by deptno order by max(sal) desc
</select>
ibatis+spring:
1.拷贝工程
2.加入 sping db pool的jar
3.加入applicationContext.xml
4.删除sqlMapConfig.xml 的tx标签
5.编写applicationContext.xml
6.去掉单例,去掉sqlMapClient的取值,加入setter,getter
7.测试
发表评论
-
遮盖层覆盖整个页面
2015-07-08 10:45 553html代码: <body topmargin= ... -
spring注解+restlet
2014-08-26 13:32 606spring注解精解: http://www.douban.c ... -
Spring使用程序方式读取properties文件
2014-07-03 10:37 487Spring使用程序方式读取properties文件 在sp ... -
用javascript取当前系统时间(年、月、日等全)
2013-07-25 14:56 527var myDate = new Date(); myDate ... -
sql--查询数据库的连接数
2013-06-07 14:04 552Oracle: select * from v$sessio ... -
jQuery中设置form表单中action值的方法
2013-04-28 18:16 1084html代码: <form id="myFo ... -
java filter
2013-04-24 23:17 831一、使浏览器不缓存页面的过滤器 Java代码 impo ... -
sql count
2013-04-23 14:33 669连接该服务器的个数: SELECT count(*) FRO ... -
关闭打开页js(兼容浏览器)
2013-04-22 13:17 810<script> function closeSe ... -
sql-修改表
2013-04-11 10:19 646如需在表中添加列,请使用下列语法: ALTER TABLE t ... -
wget 爬虫
2012-11-13 13:34 1416wget 使用指南 wget是一个从网络上自动下载文件的自由工 ... -
Struts2的整理
2012-11-13 13:31 8201、任何表现层框架都是用来帮我们实现MVC model1(js ... -
dwr的使用
2012-11-11 12:38 744Dwr使用说明 1. 将dwr的ja ... -
Ajax的使用
2012-11-11 12:37 663ajax的使用步骤: 1.需要通过JavaScript创建XM ... -
JAVA数据库连接池
2012-11-09 00:02 693JAVA数据库连接池 基 ... -
事务传播特性和事务隔离级别
2012-11-08 23:48 562事务传播特性了解事务 ... -
懒加载
2012-11-07 19:03 595get和load默认的时候都是立即检索,只有设置lazyloa ... -
HQL语句
2012-11-07 19:01 5791.实体查询 String hql = &qu ... -
类的加载和反射
2012-11-07 18:57 6381. 类的加载、连接和初始 a) 类的加载 i. 当程序主动使 ... -
部分重要SQL语句
2012-11-06 20:13 690TO_CHAR(date, 'fmt') 用于将 ...
相关推荐
Spring与iBATIS的集成 iBATIS似乎已远离众说纷纭的OR框架之列,通常人们对非常流行的Hibernate情有独钟。但正如Spring A Developer's Notebook作者Bruce Tate 和Justin Gehtland所说的那样,与其他的OR框架相比...
ibatis学习 ibatis总结 ibatis ibatis ibatis
最近想在最新的Spring5.0中集成ibatis(不是mybatis),发现已经不在支持SqlmapClientTemplate和SqlmapClientFactoryBean,于是搞了这个工具jar来进行支持如下配置 ...
《iBATIS实战》是讲述iBATIS框架的权威著作。书中既详实地介绍了iBATIS的设计理念和基础知识,也讨论了动态SQL、高速缓存、DAD框架等高级主题,还讲解了iBATIS在实际开发中的应用。《iBATIS实战》的最后给出了一个...
Manning.iBATIS.in.Action.Jan.2007.eBook-BBL.pdf MyBatis 3 User Guide Simplified Chinese.pdf MyBatis-3.0.3-Migrations.pdf MyBatis-3.0.3-User-Guide.pdf MyBatis-3-Migrations.doc MyBatis-3-Migrations.pdf ...
ibatis 乱码解决 ibatis乱码 gbk iso_8859_1 乱码
ibatis代码自动生成,ibatis代码自动生成,ibatis代码自动生成,ibatis代码自动生成
ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料ibatis资料
ibatis demo,ibatis例子,ibatis示例
ibatis 拼接字符串
iBATIS 级联iBATIS 级联iBATIS 级联
Ibatis3,手册,Ibatis3手册,Ibatis3使用手册,Ibatis3参考手册
目前网上罕见的JSF+iBATIS+MySQL示例代码,公司某软件项目所需而做的前期DEMO,只有两个Web页面,用户登录和用户列表,但已经能够说明JSF+iBATIS的典型应用方式。 MyEclipse6.5 项目工程文件,内含SQL建库指令。 ...
ibatis-2.3.4.726.jar,ibatis-2.3.0.677.jar,ibatis-2.3.3.720.jar下载,都已放入一个压缩包下。
iBATIS的是一个持久层框架,它能够自动在 Java, .NET, 和Ruby on Rails中与SQL数据库和对象之间的映射。映射是从应用程序逻辑封装在XML配置文件中的SQL语句脱钩。 iBATIS是一个轻量级的框架和持久性API适合持久化的...
ibatis教程 输入参数详解 ibatis快速入门
自己写了一个Ibatis入门文件 JDK用的1.4 ibatis用的2.3.0 一定要注意版本问题,不然出现本本不兼容很费劲,我调了一上午,注意一定要用JDK1.4 ibatis2.3.0! 数据库自己建一张简单的表就行了,特别说明 只适合新手...
一直以来ibatis的分页都是通过滚动ResultSet实现的,应该算是逻辑分页吧。逻辑分页虽然能很干净地独立于特定数据库,但效率 在多数情况下不及特定数据库支持的物理分页,而hibernate的分页则是直接组装sql,充分...
ibatis api,ibatis文档,ibatis说明文档