mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
2015-03-12 14:34
501 查看
mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
(2013-01-07 19:20:07)
转载▼
标签: | 分类: 框架 |
需要的jar包
mybatis-3.0.6.jar
mybatis-spring-1.0.2.jar
要点:
1.在spring中配置mybatis工厂类
2.在dao层使用spring注入的的工具bean对数据进行操作
整合时,可以有四种方式来使用mybatis进行数据处理。
spring 中必须的配置。
spring的配置文件中加入以下内容
Xml代码
<</span>bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<</span>property name="dataSource" ref="c3p0DataSource" />
<</span>property name="configLocation" value="/WEB-INF/config/db/MyBatisConfiguration.xml" />
<</span>property name="mapperLocations" value="/WEB-INF/config/db/*Mapper.xml" />
<</span>property name="typeAliasesPackage" value="${mybatis.alias.basepackage}" />
</</span>bean>
1.SqlSessionFactoryBean (必需)
就是中间件所需的处理类
2.dataSource (必需)
spring中数据源引用
3.configLocation (可选)
Mybatis自身的配置文件,一般用来声明别名
4.mapperLocation (可选)
mybatis的映射文件
5.typeAliasesPackage (可选)
要映射类的包路径,如果使用了这种方式,则configLocation中不必再进行声明
使用mybatis进行数据处理的四种方式(SqlSessionTemplate/SqlSessionDaoSupport/MapperFactoryBean/MapperScannerConfigurer)
不同方式的特点
SqlSessionTemplate 这个需要写配置文件,在实现类中注入sqlsession,再使用sqlsession,是细颗粒控制
SqlSessionDaoSupport 这个只需要在实现类中继承特殊类就可以使用sqlsession
MapperFactoryBean 这个要写配置文件,把对应的所有接口在配置文件中引用即可,无需写实现类
MapperScannerConfigurer 这个要写配置文件,只要给出接口所在的包即可,会自动把包中的接口引入,无需写实现类
SqlSessionTemplate
配置文件加入新配
Java代码
"sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
"0" ref="sqlSessionFactory" />
"1" value="BATCH" />
相关文章推荐
- mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
- java.lang.NoClassDefFoundError: org/mybatis/spring/mapper/MapperFactoryBean异常
- SpringMVC+Mybatis+Spring整合中org.springframework.beans.factory.BeanCreationException错误分析
- spring boot 报错 Invalid property 'mapperHelper' of bean class [org.mybatis.spring.mapper.MapperFactor
- 关于IDEA中maven整合mybatis+spring+springMVC项目中mapper文件找不到问题的解决方案(org.apache.ibatis.binding.BindingExcepti
- No setter found for property 'mapperLocation' in class 'org.mybatis.spring.SqlSessionFactoryBean' [c
- spring和mybatis整合的关键:org.mybatis.spring.mapper.MapperScannerConfigurer 类作用
- spring mvc +Mybatis3.1 整合的时候异常
- hibernate4整合spring3.1出现nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/Sess
- Spring+SpringMVC+Mybatis大整合(SpringMVC采用REST风格、mybatis采用Mapper代理)
- Mybatis3.2.1整合Spring3.1
- mybatis与spring3.1整合的四种方式 (附示例)
- spring3.1的BeanFactory与Quartz1.8整合
- mybatis和spring3.1整合
- mybatis与spring3.1整合
- Spring+SpringMVC+Mybatis大整合(SpringMVC采用REST风格、mybatis采用Mapper代理)
- org.mybatis.spring.mapper.MapperScannerConfigurer$Scanner$1
- 整合ssh Hibernate one2many 报:org.springframework.beans.factory.BeanCreationException: Error creating b
- mybatis-spring整合总结02_SqlSessionFactoryBean
- mybatis与spring3.1整合