您的位置:首页 > 数据库

从IBatis2.X 移植到IBatis3.0 sqlMapConfig and sqlMap XML 配置文件升级说明

2012-05-17 15:07 781 查看
以下将介绍 从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">
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt{background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; }新的 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">
[b]Configuration XML 变化:[/b]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>
[b]Mapping XML 变化[/b]1、根节点由 <sqlMap>  更改为 <mapper>2、属性 parameterClass 必须更改为 parameterType3、属性 resultClass 必须更改为 resultType4、属性 class 必须更改为 type5、"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 中.[b]Dynamic SQL 的变化:[/b]项目中最经常使用的动态语句是 "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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ibatis 配置文件 初学