- 浏览: 898962 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (498)
- J2EE (52)
- 数据库 (17)
- java基础 (43)
- web技术 (19)
- 程序设计 (6)
- 操作系统 (18)
- IT资讯 (7)
- 我的IT生活 (12)
- 学习笔记 (9)
- Jquery (25)
- JavaScript (18)
- spring (40)
- Hibernate (12)
- Struts (10)
- YUI (2)
- Extjs (22)
- .net (0)
- Eclipse (10)
- 社会主义 (2)
- 服务器 (9)
- CSS (8)
- 网络安全 (16)
- 版本控制 (9)
- PHP (2)
- Oracle (42)
- SQL server (1)
- Mysql (11)
- 项目管理 (3)
- 开发工具使用 (10)
- SQL语句 (7)
- Perl (0)
- Shell (6)
- 漏洞 (4)
- ibatis (5)
- hacker (2)
- SQL注入 (6)
- Hacker工具 (2)
- 入侵和渗透 (7)
- 插件/组件 (2)
- 最爱开源 (5)
- 常用软件 (2)
- DOS (1)
- HTML (2)
- Android (9)
- CMS (1)
- portal (8)
- Linux (7)
- OSGI (1)
- Mina (5)
- maven (2)
- hadoop (7)
- twitter storm (2)
- sap hana (0)
- OAuth (0)
- RESTful (1)
- Nginx (4)
- flex (1)
- Dubbo (1)
- redis (1)
- springMVC (1)
- node.js (1)
- solr (2)
- Flume (1)
- MongoDB (2)
- ElasticSearch (1)
最新评论
-
M_drm:
请问要怎么设置浏览器才不报没权限呢?
用JS在页面调用本地可执行文件的方法(ACTIVEX) -
Alexniver:
官方文档。When importing data into I ...
mysql导入数据过慢 解决方法 -
camelwoo:
我记得 Criteria 可以做连接查询与子查询,也可以做分页 ...
Hibernate总结篇二 -
zhenglongfei:
楼主如果SubKeyName 这个节点不存在,怎么办??怎么用 ...
Java操作注册表 -
yxx676229549:
用log4j 2 了
logback
ormmping的思想相信不用多说大家都明白了,在这里我选择的是ibatis 由于手动的控制事务会带来很多额外的工作,同时也没有很好的体现面向对象的思想,因而利用ibatis整合spring ;由于要注意的细节非常多现在整理核心步骤如下:
配置前需把ibatis的jar导入到工程,这里从略
一 web.xml的配置
二 applicationContext.xml文件的配置
三 sqlmap-config.xml 文件配置
四 ormpping文件的配置(student_oracle.xml等 )
五 实体bean代码
六 dao实现类
七 业务层实现类
配置前需把ibatis的jar导入到工程,这里从略
一 web.xml的配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>InserttoDBServlet</servlet-name> <servlet-class>service.InserttoDBServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>InserttoDBServlet</servlet-name> <url-pattern>/InserttoDBServlet</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:applicationContext.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>TestServlet</servlet-name> <servlet-class>test.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/servlet/TestServlet</url-pattern> </servlet-mapping> <filter> <filter-name>ExtFilter</filter-name> <filter-class>filter.ExtFilter</filter-class> </filter> <filter-mapping> <filter-name>ExtFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
二 applicationContext.xml文件的配置
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource_oracle" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test" /> <property name="username" value="root" /> <property name="password" value="root" /> <property name="initialSize" value="1" /> <property name="maxActive" value="4" /> </bean> <bean id="dataSource_oracle" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="oracle.jdbc.OracleDriver" /> <property name="url" value="jdbc:oracle:thin:@192.168.100.235:1521:mpptest" /> <property name="username" value="gmcc" /> <property name="password" value="skywin" /> <property name="initialSize" value="1" /> <property name="maxActive" value="4" /> </bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="classpath:sqlmap-config.xml" /> <property name="dataSource" ref="dataSource_oracle" /> </bean> <bean id="baseTxService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="transactionManager" /> <property name="proxyTargetClass" value="true" /> <property name="transactionAttributes"> <props> <prop key="insert*">PROPAGATION_REQUIRED</prop> <prop key="query*">readOnly</prop> <prop key="get*">readOnly</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="studentDao" class="dao.StudentDaoImpl"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean> <bean id="studentService" class="service.StudentServiceImpl"> <property name="studentDao" ref="studentDao"></property> </bean> <bean id="studentServiceProxy" parent="baseTxService"> <property name="target" ref="studentService"></property> </bean> <bean id="treeService" class="service.TreeServiceImpl_map"> <property name="treeDao" ref="treeDao"></property> </bean> <bean id="treeServiceProxy" parent="baseTxService"> <property name="target" ref="treeService"></property> </bean> <bean id="treeDao" class="dao.TreeDaoImpl"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean> <bean id="xmlTreeService" class="service.XmlTreeServiceImpl"></bean> </beans>
三 sqlmap-config.xml 文件配置
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <sqlMap resource="student_oracle.xml" /> <sqlMap resource="treeNode_oracle.xml" /> </sqlMapConfig>
四 ormpping文件的配置(student_oracle.xml等 )
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap namespace="Student_oracle"> <resultMap id="result" class="entity.Student"> <result property="stuId" column="id" columnIndex="1" /> <result property="name" column="stuname" columnIndex="2" /> <result property="password" column="stupassword" columnIndex="3" /> </resultMap> <insert id="insertToDb"> insert into test_qjk_stu(id,stuname,stupassword)values(#stuId#,#name#,#password#) </insert> <insert id="insertTest"> <selectKey resultClass="Integer" keyProperty="stuId"> SELECT test_qjk_stu_seq.nextval FROM DUAL </selectKey> insert into test_qjk_stu(id,stuname,stupassword)values(#stuId#,#name#,#password#) </insert> </sqlMap>
五 实体bean代码
package entity; import java.util.Date; public class Student { private Integer stuId; private String name; private Date birthday; private String sex; private String passport; private byte[] password; public byte[] getPassword() { return password; } public void setPassword(byte[] password) { this.password = password; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassport() { return passport; } public void setPassport(String passport) { this.passport = passport; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public Integer getStuId() { return stuId; } public void setStuId(Integer stuId) { this.stuId = stuId; } public String toString(){ return "stuid:"+stuId+"---name:"+name+"---passport:"+passport+"-----sex:"+sex+"--birthday:"+birthday; } }
六 dao实现类
package dao; import java.sql.SQLException; import java.util.List; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; import util.Print; import entity.Student; public class StudentDaoImpl extends SqlMapClientDaoSupport implements StudentDao { public void insertToDb(Student stu) { getSqlMapClientTemplate().insert("insertToDb", stu); } public Student queryStuById(Integer id) { Student stu=(Student) getSqlMapClientTemplate().queryForObject("queryStuById", id); Print.contrlPrint("dao查到的对象是"+stu); return stu; } public List getSomeStu(int start, int pageSize) { System.out.println("dao ---start"+start); System.out.println("dao ---pageSize"+pageSize); List list=getSqlMapClientTemplate().queryForList("queryStudent", null, start, pageSize); System.out.println("dao---list---size"+list.size()); return list; } public Long getStudentCount() { return (Long) getSqlMapClientTemplate().queryForObject("getStudentCount", null); } public void delStuById(Long stuId) { getSqlMapClientTemplate().delete("delStuById", stuId); } public void updateStudent(Student stu) { getSqlMapClientTemplate().update("updateStudent", stu); } public List test(){ return getSqlMapClientTemplate().queryForList("test",null); } public Integer insertTest(Student stu) { Print.contrlPrint("调用了insertTest"); return (Integer) getSqlMapClientTemplate().insert("insertTest", stu); } }
七 业务层实现类
package service; import java.util.List; import util.Tools; import dao.StudentDao; import entity.Student; public class StudentServiceImpl implements StudentService { private StudentDao studentDao; public void insertToDb(Student stu) { studentDao.insertToDb(stu); // Integer id=studentDao.insertTest(stu); // System.out.println("插入记录的id是"+id); } public StudentDao getStudentDao() { return studentDao; } public void setStudentDao(StudentDao studentDao) { this.studentDao = studentDao; } public Student queryById(Integer id) { return studentDao.queryStuById(id); } public List getSomeStu(int start, int pageSize) { return studentDao.getSomeStu(start, pageSize); } public String getResponseJson(int start, int pageSize) { List list=getSomeStu(start, pageSize); Long count=getStudentCount(); return Tools.getResponseJson(list,count); } public Long getStudentCount() { return studentDao.getStudentCount(); } public void delStuById(Long stuId) { studentDao.delStuById(stuId); } public void updateStudent(Student stu) { studentDao.updateStudent(stu); } }
发表评论
-
使用EhCache和Spring AOP实现计算结果缓存
2012-08-07 10:47 1035原文:http://kim-miao.iteye.com/bl ... -
wsdl axis2 spring
2012-08-02 17:06 880http://renxiangzyq.iteye.com/ ... -
spring 监听器 IntrospectorCleanupListener简介
2012-08-02 17:00 1033"在服务器运行过程中,Spring不停的运行的计划任 ... -
Quartz的cron时间表达式
2012-04-11 17:33 1281一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素 ... -
Spring 框架的设计理念与设计模式分析
2012-03-06 13:49 966Spring 框架的设计理念与设计模式分析 http://ww ... -
Spring事务配置的五种方式
2012-03-04 10:40 1370前段时间对Spring的事务配置做了比较深入的研究,在此之间对 ... -
Spring技术内幕:深入解析Spring架构与设计原理(转)
2011-07-01 16:58 1141http://jiwenke.iteye.com/blo ... -
AOP 的利器:ASM 3.0 介绍
2011-06-29 13:48 1353AOP 的利器:ASM 3.0 介绍 http://www ... -
在非web环境中使用spring
2011-06-29 13:34 4205Spring再强大,也要面对降临的问题--因为Spr ... -
Spring LDAP 1.3.1 发布
2010-12-05 21:17 1170http://www.iteye.com/news/18834 ... -
Spring MVC 3.x annotated controller的几点心得体会
2010-12-01 09:53 2447最近拿Spring MVC 3.x做项目,用了最新的系列相关A ... -
Spring开始关注移动应用开发,发布Spring Mobile,Spring Android
2010-11-29 11:01 3346近日,Roy Clarkson发布了S ... -
SSH全注解-annotation详细配置
2010-11-21 18:50 2452如果有点SSH框架的经验,这个很好理解.配置不难. 配置an ... -
spring安全框架应用
2010-10-11 22:09 3228第一步 将spring-security-core-2.0. ... -
spring3.0.4 新增加的注解(mvc:resources)
2010-08-23 22:19 8917从spring3.0.3发布以后一直等待spring3.0.4 ... -
spring2.0与spring2.5的差别
2010-08-22 00:14 1622资料:http://ajava.org/online/spri ... -
利用Spring框架封装的JavaMail现实同步或异步邮件发送
2010-08-21 23:25 5531利用Spring框架封装的JavaMail现实同步或异步邮件发 ... -
领略Spring 3.x 时代的Spring MVC
2010-08-21 23:20 1404鼎鼎大名的Spring框架3.0版在12月5日由其作者之一—— ... -
使用 Spring 2.5 基于注解驱动的 Spring MVC
2010-08-21 23:16 1002概述 继 Spring 2.0 对 Spring MVC ... -
Spring2.0压缩包目录说明
2010-08-21 22:44 5341、 Spring2.0压缩包目录说明 aspectj目录 ...
相关推荐
整合ibatis和spring,通过spring的ioc框架调用ibatis进行数据库访问,并向数据库中插入数据
▲Struts+Spring和iBatis整合 这是演示范例,不设计高级知识,易看易懂。 演示了▲Struts+Spring和iBatis的整合完整步骤!~ 包学包会!~~~~~~~~~~
spring与ibatis整合集成实例 spring与ibatis整合集成实例
spring ibatis整合所需jar包
spring_ibatis整合案例
struts2 + spring + ibatis 整合例子,仓库:search.maven.org
struts2、spring、ibatis整合实例 struts2、spring、ibatis整合实例 struts2、spring、ibatis整合实例 struts2、spring、ibatis整合实例
Struts+Spring+Ibatis整合框架搭建配置文档
iBatis和Spring整合 iBatis和Spring整合
Spring对IBatis的整合 10.3 Spring对IBatis的支持 Spring对IBatis提供了完善的内建支持。使用Spring提供的IBatis辅助类,可以大大简化原有的IBatis访问代码。这些辅助类位于org.springframework.orm.ibatis包下,...
struts2+spring+ibatis整合项目实例
资源是spring3结合ibatis 的项目,内有项目详解文档。是新手学习绝世宝典哦。不可错过~
Struts2+Spring+Ibatis ,里面实现了登录功能, 可供初学者学习,代码很详细, 注释很多, 还可以用于做项目
spring3.2与Ibatis整合,在servlet中获取bean
简单的 struts2 spring ibatis 整合架构
Struts2+Spring+Ibatis整合的简单人事管理系统 没分了,转载过来的,有需要的看看吧,我觉得不错~~
里面有spring+struts2+ibatis整合的jar包,
Struts+Spring+Ibatis整合的Jar包
com.ibatis.dao.client.*等缺少ibatis包的导入 spring+ibatis整合web
struts1 spring ibatis整合项目源码struts1 spring ibatis整合项目源码struts1 spring ibatis整合项目源码struts1 spring ibatis整合项目源码struts1 spring ibatis整合项目源码struts1 spring ibatis整合项目源码