Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring http://www.cnblogs.com/daxin/p/3545040.html

 

 

spring与mybatis三种整合方法

http://blog.csdn.net/skylovedaim/article/details/18553081
本文主要介绍Spring与Mybatis三种常用整合方法,需要的整合架包是mybatis-spring.jar,可通过链接
http://code.google.com/p/mybatis/下载到。  1、采用数据映射器(MapperFactoryBean)的方式,不用写mybatis映射文件,采用注解方式提供相应的sql语句和输入参数。

(1)Spring配置文件:

数据映射器UserMapper,代码如下:

dao接口类UserDao,代码如下:

dao实现类UserDaoImpl2,,代码如下:

2、采用接口org.apache.ibatis.session.SqlSession的实现类org.mybatis.spring.SqlSessionTemplate。
mybatis中, sessionFactory可由SqlSessionFactoryBuilder.来创建。

MyBatis-Spring 中,使用了SqlSessionFactoryBean来替代。
SqlSessionFactoryBean有一个必须属性dataSource,
另外其还有一个通用属性configLocation(用来指定mybatis的xml配置文件路径)。
(1)Spring配置文件:

(2)mybatis总配置文件sqlMapConfig.xml:

(3)实体类映射文件user.map.xml:

(4)dao层接口实现类UserDaoImpl:

附加MyBatis SqlMapConfig.xml例子

使用mapperLocations属性错误: Error parsing Mapper XML
可能解决方式1: http://www.cnblogs.com/huanmieuroshui/archive/2012/12/18/2822754.html
可能解决方式2: <property name=”mapperLocations” value=”classpath:com/pandy/app/bean/mapper/*Mapper.xml” />, 这个属性是直接扫描Mapper.xml文件, 而不是查找SqlMapConfig.xml文件.

3、采用抽象类org.mybatis.spring.support.SqlSessionDaoSupport提供SqlSession。

(1)spring配置文件:

(2) dao层接口实现类UserDaoImpl3: