惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
腾讯CDC
GbyAI
GbyAI
I
InfoQ
博客园 - Franky
G
Google Developers Blog
Last Week in AI
Last Week in AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
Vercel News
Vercel News
博客园_首页
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
V
V2EX
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏
The GitHub Blog
The GitHub Blog

博客园 - 雨中漫步的太阳

基于跨数据库的事务的一个讨论,希望参考下大家的意见 Wave帮助、技巧、术语集 .NET正则基础——.NET正则类及方法应用[转载] 按钮单击ThickBox弹出窗口 推荐一款界面设计工具 Balsamiq Mockups jQuery.extend的用法 转载 qq2009 好像和金山词霸屏幕取词有冲突 错误 1 error C2664: 'TextOutW' : cannot convert parameter 4 from 'const char [5]' to 'LPCWSTR' 也发一个有道第二题的算法,练练脑子 使用commons-logging和log4j记录日志[转载] 动手改造Ibatis,使其支持文件系统存储数据列 之 看我如何给ResultMap增加属性 发一个 Window Live Writer 插件 SyntaxHighlight 代码样式 700万数据随机取10条仅用不到10ms? 动手改造Ibatis,使其支持文件系统存储数据列 之 源码下载编译和SqlMapConfig解析 IBAtisHelper 源代码放出,需要的下载吧 动手改造Ibatis,使其支持文件系统存储数据列 预览 大家讨论下,结合文件系统,给数据库瘦身方案的可行性 Ibatis SelectKey iBatis resultMap groupBy属性使用心得[转载]
从IBatis2.X 移植到IBatis3.0 sqlMapConfig and sqlMap XML ...
雨中漫步的太阳 · 2009-11-09 · via 博客园 - 雨中漫步的太阳

以下将介绍 从Ibatis2.X 升级到 Ibatis3.0 配置文件的升级,这仅仅是一个初步的修改意见,我已经决定并开始移植工作,

我没有很多的时间去测试它,所以目前我不能保证他完全正确,但是我会通过你们的建议让他逐步的完善准确.

新的 sqlMapConfig.xml DTD:

<!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-config.dtd">

新的 sqlMap (*.map.xml) DTD:

<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD iBatis Mapper 3.0 //EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
Configuration XML 变化:
1、根节点标签 由 <sqlMapConfig>  更改为  <configuration>
2、<settings x="y" foo="bar"/>  更改为如下写法

<settings>

    <setting name="x" value="y"/>

    <setting name="foo" value="bar"/>

</settings>

3、<typeAlias> 标签必须从 <sqlMap> 节点移动到 <configuration><typeAliases></typeAliases></configuration> 内

如下示例:

<configuration>
	<settings>
	...
	</settings>
	<typeAliases>
		<typeAlias ... />
	</typeAliases>
</configuration>
 
Mapping XML 变化

1、根节点由 <sqlMap>  更改为 <mapper>

2、属性 parameterClass 必须更改为 parameterType

3、属性 resultClass 必须更改为 resultType

4、属性 class 必须更改为 type

5、"groupBy" 属性已经删除.

在Ibatis2.X 时候,groupBy 使用方式如下

<resultMap id="productRM" type="product" groupBy="id">
     <result property="id" column="product_id"/>
     <result property="name" column="product_name"/>
     <result property="category" column="product_category"/>
     <result property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>

在3.0中使用方式如下:

<resultMap id="productRM" type="product" >
	<id property="id" column="product "/>
	<result property="name " column="product_name "/>
	<result property="category " column="product_category "/>
	<collection property="subProducts" resultMap="Products.subProductsRM"/>
</resultMap>

其他的变更对比如下:

Ibatis2.X:

<resultMap id="invoiceRM" type="invoice" extends="Invoice.abstractInvoiceRM">
	<result property="client" resultMap="Client.clientRM"/>
	<result property="accounts" column="invoiceNumber=INVOICE_NUMBER" select="Invoice.getAccountsSql"/>
	<result property="products" column="productGroup=PRODUCT_GROUP_ID" select="Invoice.getProductsSql"/>
</resultMap>

Ibatis3.0:

<resultMap id="agreementDetailRM" type="agreement" extends="Agreement.agreementRM">
	<association property="client" resultMap="Agreement.clientRM"/>
	<collection property="accounts" column="agreementNumber=AGREEMENT_NUMBER" select="Agreement.getAccountsSql"/>
	<collection property="products" column="serviceGroupId=SERVICE_GROUP_ID" select="Agreement.getProductsSql"/>
</resultMap>

上面的示例中 id被定义在父 result map 中.

Dynamic SQL 的变化:

项目中最经常使用的动态语句是 "isNotNull". 此处将给出一个替代的方案:

比如下面的写法:

<isNotNull.*?property=\"(.*?)\"

可以这样写:

<if test="$1 != null"
注意:如果使用了<if ..> 关闭标签也必须由</isNotNull> 更改为</if>
 
原文地址:http://opensource.atlassian.com/confluence/oss/display/IBATIS/Porting+sqlMapConfig+and+sqlMap+XML+from+2.x+to+3.0
用自己蹩脚的英文加工具翻译的本篇文章 以备自己查阅方便,如有翻译不当之处望指正.