struts,spring,mybatis框架整合
2014-03-21 17:29
441 查看
(1)完成strut的搭建(笔记中有)
(2)整合spring
引入的jar包:
cglib-nodep-2.1_3.jar
commons-collections-3.1.jar
commons-dbcp.jar
commons-fileupload-1.3.jar
commons-io-2.2.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
commons-pool-1.6.jar
spring-aop-3.0.6.RELEASE.jar
spring-asm-3.0.6.RELEASE.jar
spring-beans-3.0.6.RELEASE.jar
spring-context-3.0.6.RELEASE.jar
spring-core-3.0.6.RELEASE.jar
spring-expression-3.0.6.RELEASE.jar
spring-jdbc-3.0.6.RELEASE.jar
spring-orm-3.0.6.RELEASE.jar
spring-tx-3.0.6.RELEASE.jar
spring-web-3.0.6.RELEASE.jar
Web.xml的配置,增加监听:
<!-- 加载spring的配置文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置spring配置文件加载的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
applicationContext.xml的配置很重要的一步,
<!-- 配置DataSource数据源 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!-- 配置事务管理器,注意这里的dataSource和SqlSessionFactoryBean的dataSource要一致,不然事务就没有作用了 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 创建SqlSessionFactory,同时指定数据源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml"></property>
</bean>
(3)a.整合mybatis,需要引入两个包
mybatis-3.1.0.jar
mybatis-spring-1.2.0.jar
还有db2的驱动包:
db2driver-9.0.jar
db2driver-lisence-9.0.jar
db2jcc.jar
b.配置mybatis.xml
c.sqlmap的写法(这个资料到处有,V6里面也是一样,对mybatis封装很少)
(4)编写测试类(可以在此基础上封装)
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
SqlSessionFactory sessionFactory= (SqlSessionFactory)factory.getBean("sqlSessionFactory");
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sessionFactory);
List list=(List)sqlSessionTemplate.selectList("selectAllUser");
(2)整合spring
引入的jar包:
cglib-nodep-2.1_3.jar
commons-collections-3.1.jar
commons-dbcp.jar
commons-fileupload-1.3.jar
commons-io-2.2.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
commons-pool-1.6.jar
spring-aop-3.0.6.RELEASE.jar
spring-asm-3.0.6.RELEASE.jar
spring-beans-3.0.6.RELEASE.jar
spring-context-3.0.6.RELEASE.jar
spring-core-3.0.6.RELEASE.jar
spring-expression-3.0.6.RELEASE.jar
spring-jdbc-3.0.6.RELEASE.jar
spring-orm-3.0.6.RELEASE.jar
spring-tx-3.0.6.RELEASE.jar
spring-web-3.0.6.RELEASE.jar
Web.xml的配置,增加监听:
<!-- 加载spring的配置文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置spring配置文件加载的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
applicationContext.xml的配置很重要的一步,
<!-- 配置DataSource数据源 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!-- 配置事务管理器,注意这里的dataSource和SqlSessionFactoryBean的dataSource要一致,不然事务就没有作用了 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 创建SqlSessionFactory,同时指定数据源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml"></property>
</bean>
(3)a.整合mybatis,需要引入两个包
mybatis-3.1.0.jar
mybatis-spring-1.2.0.jar
还有db2的驱动包:
db2driver-9.0.jar
db2driver-lisence-9.0.jar
db2jcc.jar
b.配置mybatis.xml
c.sqlmap的写法(这个资料到处有,V6里面也是一样,对mybatis封装很少)
(4)编写测试类(可以在此基础上封装)
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
SqlSessionFactory sessionFactory= (SqlSessionFactory)factory.getBean("sqlSessionFactory");
SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sessionFactory);
List list=(List)sqlSessionTemplate.selectList("selectAllUser");
相关文章推荐
- struts,spring和mybatis框架整合
- spring+struts+mybatis三大框架整合配置
- 三大框架整合struts+spring+mybatis
- myeclipse+struts+spring+mybatis+mave的框架整合---spring+mybatis
- struts+spring+mybatis框架整合
- Struts+spring+mybatis框架整合
- 整合Struts,Spring,mybatis三个框架的helloworld
- struts2+spring+mybatis框架整合详细介绍
- 企业级框架整合Springmvc+mybatis+restful+bootstrap
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- SSM框架整合:SpringMVC + Spring + MyBatis+Maven
- spring和mybatis整合框架
- Mybatis框架学习(四)—查询缓存与spring的整合开发
- MyBatis代码实例系列-05:Mybatis初步整合Spring + Spring MVC框架,实现Web请求实例
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- spring 框架整合mybatis的源码分析
- 1.Maven 搭建Struts、spring、mybatis框架-安装Maven环境
- 整合Struts、Spring、Mybatis
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)