mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
来源:互联网 发布:什么软件有软文 编辑:程序博客网 时间:2024/04/20 11:41
mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
(2013-01-07 19:20:07)转载▼
标签:
mybatis
spring3.1
整合
mvc
oracle
分类: 框架因spring3发布时mybatis还没有出正式版本,所以spring没有整合最新的mybatis.不过社区倒是开发了一个中间件。
需要的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
3.configLocation
4.mapperLocation
5.typeAliasesPackage (可选)
使用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"/>
- "sqlSession"
0 0
- mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
- mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
- spring整合mybatis(基于MapperFactoryBean)
- spring-mybatis整合一MapperFactoryBean
- spring整合mybatis(不基于MapperFactoryBean)
- Spring-MyBatis 之 MapperFactoryBean
- spring mybatis 之MapperFactoryBean
- mybatis与spring3.1整合
- mybatis与spring3.1整合
- mybatis与spring3.1整合
- mybatis与spring3.1整合
- mybatis与spring3.1整合
- mybatis与spring3.1整合
- mybatis与spring3.1整合
- mybatis与spring3.1整合----
- mybatis与spring3.1整合
- 5238 ERROR 2017-10-17 09:30:16396 org.mybatis.spring.mapper.MapperFactoryBean Error while adding the
- 整合Mybatis 与 Spring3
- AlertDialog使用
- 云服务架构学习
- 程序员编程面试取胜的8个技巧
- 综合第一篇(迷上了Quora)
- ogre学习笔记-Intermediate Tutorial 567
- mybatis与spring3.1整合(org.mybatis.spring.mapper.MapperFactoryBean)
- Sicily 7974. Integer Lists
- 敢于亮剑,我为自己加油
- 你需要掌握的三种编程语言
- 发现一片写的很好的c++基础文章
- Linux下静态库和动态库
- Java中的内部类
- 杭电acm2021
- 【Java技术点滴】——代理模式及其对事务封装