spring与mybatis三种整合方法
来源:互联网 发布:济南行知小学学区划分 编辑:程序博客网 时间:2024/06/11 05:39
本文主要介绍Spring与Mybatis三种常用整合方法,需要的整合架包是mybatis-spring.jar,可通过链接
http://code.google.com/p/mybatis/下载到。
1、采用数据映射器(MapperFactoryBean)的方式,不用写mybatis映射文件,采用注解方式提供相应的sql语句和输入参数。
(1)Spring配置文件:
<!-- 引入jdbc配置文件 -->
<context:property-placeholder location="jdbc.properties"/>
<!--创建jdbc数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>
<!-- 创建SqlSessionFactory,同时指定数据源-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<!--创建数据映射器,数据映射器必须为接口-->
<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.xxt.ibatis.dbcp.dao.UserMapper" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<bean id="userDaoImpl2" class="com.xxt.ibatis.dbcp.dao.impl.UserDaoImpl2">
<property name="userMapper" ref="userMapper"/>
</bean>
数据映射器UserMapper,代码如下:
mybatis中, sessionFactory可由SqlSessionFactoryBuilder.来创建。
(1)Spring配置文件:
(1)spring配置文件:
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- mybatis注解详解
- mybatis与spring整合(基于配置文件)
- 基于注解的mybatis和spring整合
- MyBatis多参数传递之注解方式示例
- Mybatis配置文件分析
- spring与mybatis三种整合方法
- Spring MVC 框架搭建及详解
- MyBatis+Spring 基于接口编程的原理分析
- Volley.jar 制作方法
- 最长回文子串
- DirectX 9.0c游戏开发手记之“龙书”第二版学习笔记之7: Chap9: Color
- Reverse words
- 算法学习之排序算法:插入排序(直接插入排序、折半插入排序、2-路插入排序)
- 关于编程学习的七点思索