根据SSH整合的经验,先整合spring与ibatis(基于扫描+注解)
1.加入spring相关架包以及ibatis相关一个架包
aspectjrt.jar
aspectjweaver.jar
cglib-nodep-2.1_3.jar
common-annotations.jar
commons-logging-1.1.1.jar
log4j-1.2.14.jar
spring.jar
c3p0-0.9.1.2.jar
ibatis.rar
2.主要配置
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 通过注解方式把类交给spring -->
<context:component-scan base-package="com.ssi" />
<!-- 把Ibatis集成到spring -->
<!-- 减少数据库连接 采用数据源 C3P0比DBCP(dbcp+pool)效率高一点 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" dependency-check="none">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl"
value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="minPoolSize" value="1" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="25000" />
<property name="acquireIncrement" value="1" />
<property name="acquireRetryDelay" value="1000" />
<property name="acquireRetryAttempts" value="30" />
<property name="initialPoolSize" value="3" />
<property name="idleConnectionTestPeriod" value="1800" />
<property name="testConnectionOnCheckin" value="true" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
<property name="useTransactionAwareDataSource">
<value>true</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="sqlMapClient" />
</property>
</bean>
<!--Spring很重要的一个服务:配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 使用基于注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings cacheModelsEnabled="true" useStatementNamespaces="true"/>
<!-- 此处开始添加SqlMap配置文件 -->
<sqlMap resource="com/ssi/bean/Users.xml" />
</sqlMapConfig>
Users.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>
<!-- 该属性是为了减少书写com.elifefly.User的次数而已 -->
<typeAlias alias="Users" type="com.ssi.bean.Users" />
<!-- 条件查询 parameterClass标识传入参数类型 忽略大小写 -->
<select id="selectUserById" parameterClass="int" resultClass="Users">
select * from users where id=#id#
</select>
<!-- 带多个参数 查询-->
<parameterMap class="java.util.HashMap" id="parameterMap">
<parameter property="name" />
<parameter property="password" />
</parameterMap>
<select id="selectUserByMap" parameterMap="parameterMap"
resultClass="Users">
select * from users where name=? and password=?
</select>
</sqlMap>
详细下载实例....
分享到:
相关推荐
struts2 + spring2.5 + ibatis2.3.4整合包文件,包括了SSI框架整合开发所需的全部文件
分为:struts2.1.8 + spring 2.5 + ibatis 2 整合开发包_ _01部分 struts2.1.8 + spring 2.5 + ibatis 2 整合开发包_ _02部分 只要将这两个包全下载下来,就可以搭建struts2.1.8 + spring 2.5 + ibatis2整合开发的...
分为:struts2.1.8 + spring 2.5 + ibatis 2 整合开发包_ _01部分 struts2.1.8 + spring 2.5 + ibatis 2 整合开发包_ _02部分 只要将这两个包全下载下来,就可以搭建struts2.1.8 + spring 2.5 + ibatis2整合开发的...
整合了Ibatis+struts2.0+Spring2.5的增、删、改、查和调用存储过程
struts1.3+spring2.5+ibatis2.3.4整合
参照jpetstore做出的Struts1.1+spring2.5+ibatis2.3+Ajax的整合、从页面输入学生的Id、光标离开后、页面利用无刷新技术从数据库取出显示在页面上。
struts2+ibatis2.x+spring2.5整合的一个demo 适合新手学习
Ibatis2.3,Struts1.3,Spring2.5框架整合简单实例代码,用了一周的业余时间,终于调通了。有需要的可以下载。
Struts2.0+Springframework2.5+ibatis2.3完美整合实例
本演示示例主要使用目前最新,最流行技术Struts2.1 +Spring 2.5.1+ibatis2.3整合开发而成,这与我以前发布的版本中最大特色是整合了Spring2.5.1中的注解功能和半自动化工具ibatis技术,这是本示例的两大特色,简化了配置...
3个框架的整合 log4j 以及上传的例子
包括ssi框架整合所需包,配置文件如何配置,如何使用
NULL 博文链接:https://hjl19.iteye.com/blog/395563
Struts2.0+Springframework2.5+ibatis2.3完美整合用户登录及增删改查示例
用Struts2,Spring,Ibatis整合的框架,前端数据显示用jquery 中的ajax请求,返回json格式的数据
本实例为struts2.0+spring2.5+ibatis2.3框架。 一、解压后先建立数据库,名为:shequ(本例采用的是MySQL5.5) 二、利用shequ.sql文件,初始化数据库。 三、部署工程,运行。 ibatis
培训信息发布平台v1.0(企业端) ...这个项目是在以前做过的一个小项目的基础上整理而得,实现的功能很简单,还很不完备,只是那时学习struts2 + Spring2.5 + iBatis2.3 + ExtJs3.0整合开发的一个习作。
SSI框架整合 开发工具: MyEclipse8.5 框架版本: struts2、spring2.5、ibatis
利用spring2.5 + ibatis 2.3 + struts2.1实现三个框架的整合,功能包括增、删、改、查以及存储过程的处理,同时加进了Junit测试框架。