在2010年6月16日,iBATIS团队决定从apache迁出并迁移到Google Code,并更名为MyBatis。目前iBATIS 2.x和MyBatis 3不是100%兼容的,如配置文件的DTD变更,SqlMapClient直接由SqlSessionFactory代替了,包名也有com.ibatis变成org.ibatis等等。
ibatis 3.x和MyBatis是兼容的,只需要将DTD变更一下就可以了。
当前在MyBatis之前,我们一直用的都是ibatis,这里先介绍spring对ibatis的集成。
一:Spring整合ibatis
spring整合ibatis首先需要导入相关jar包:
spring-orm-3.2.0.RELEASE.jar (提供SqlMapClientFactoryBean,SqlMapClientDaoSupport等类。遗憾的是spring自3.2.*版本之后已经废弃了
SqlMapClientDaoSupport。)
mybatis-2.3.5.jar (提供com.ibatis.sqlmap.client.SqlMapClient类)
项目结构如下:
首先是配置文件配置,ibatis的总配置文件
sqlMapConfig.xml(可随意命名)如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings cacheModelsEnabled="false" enhancementEnabled="true" lazyLoadingEnabled="true" maxRequests="64" maxSessions="32" maxTransactions="16"
useStatementNamespaces="false"/>
<!--引入映射的文件-->
<sqlMap resource="sqlMap/account.xml"/>
</sqlMapConfig>
在sqlMapConfig.xml中引入了表和Vo的映射文件
account.xml:
其中account表的