ibatis2到mybatis的转变

Ibatis2 到 mybatis3 的转变
New DTDs
l DTD:
<!DOCTYPE configuration PUBLIC "-////DTD Config 3.0//EN" "/dtd/mybatis-3-config.dtd">
New sqlMap (*.l) DTD:
<!DOCTYPE mapper PUBLIC "-////DTD Mapper 3.0//EN" "/dtd/mybatis-3-mapper.dtd">
Configuration
Root configuration tag <sqlMapConfig> is now <configuration>
Settings
Within the root configuration tag:
<settings x="y" foo="bar"/>
is now:
<settings> 
    <setting name="x" value="y"/> 
    <setting name="foo" value="bar"/> 
</settings>
and
<settings useStatementNamespaces="true"/>
can be removed, since the use of namespaces has become mandatory.
<typeAlias>
<typeAlias> must be moved out of the <sqlMap> element to <configuration><typeAliases></typeAliases></configuration>
<configuration> 
    <settings> 
    ... 
    </settings> 
    <typeAliases> 
        <typeAlias ... /> 
    </typeAliases> 
</configuration>
<transactionManager> and <dataSource>
<transactionManager type="JDBC" commitRequired="false"> 
    <dataSource type="your.package.CustomDataSourceFactory" /> 
</transactionManager>
is now:
<environments default="env"> 
    <environment id="env"> 
        <transactionManager type="JDBC"> 
            <property name="commitRequired" value="false"/> 
        </transactionManager> 
        <dataSourcemsinfo type="your.package.CustomDataSourceFactory" /> 
    </environment> 
</environments>
<sqlMap>
<sqlMap resource=... /> 
<sqlMap resource=... /> 
<sqlMap resource=... />
is now:
<mappers> 
    <mapper resource=... /> 
</mappers>
Mapping
The root element <sqlMap> is now <mapper>
The attribute parameterClass should be changed to parameterType
The attribute resultClass should be changed to resultType
The attribute class should be changed to type
the columnIndex attribute does not exist anymore for the <result> tag
The groupBy attribute has been eliminated. Here is an example of groupBy from a 2.x sqlMap:
<resultMap id="productRM" class="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>
New:
<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>
Nested resultMaps
These should now be specified using the <association> tag.
<resultMap ...> 
    <result property="client" resultMap="Client.clientRM"/> 
    ... 
</resultMap>
is now:
<resultMap ...> 
    <association property="client" resultMap="Client.clientRM"/> 
    ... 
</resultMap>
<parameterMap>
Although this tag is deprecated, it can be used as in iBatis 2. However for versions up to 3.0.3 there is a bug when using type="map" and not specifying javaType for a parameter.
This will result in
There is no getter for property named '...' in 'interface java.util.Map'   
This should be solved in MyBatis 3.0.4. For versions 3.0.3 and earlier the workaround is to explicitly specify javaType.
Inline parameters
#value#
is now:
#{value}
jdbcType changes
jdbcType="ORACLECURSOR"
is now:
jdbcType="CURSOR"
and
jdbcType="NUMBER"
is now:
jdbcType="NUMERIC"
Stored procedures
the <procedure> tag doesn't exist anymore. Use <select>, <insert> or <update>.
<procedure id="getValues" parameterMap="getValuesPM"> 
    { ? = Values(p_id => ?) } 
</procedure>
is now:
<select id="getValues" parameterMap="getValuesPM" statementType="CALLABLE"> 
    { ? = Values(p_id => ?)} 
</select>
If you're calling an insert procedure that returns a value, you can use <select> instead of <insert>, but make sure to specify useCache="false" and flushCache="true". You'll also have to force a commit.
for stored procedures that return a cursor, there is a bug (see  issue 30 ) when using nested result maps (i.e. the output parameter's resultMap contains an <association> tag with the resultMap attribute). As long as the issue is not fixed, you have to specify the resultMap of the output parameter on the statement itself as well, or the nested resultMap will not be populated.

本文发布于:2024-09-23 23:25:28,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/380572.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:配置文件   连接   数据库
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议