mybatis 中javaType和OfType 的区别

时间:2023-03-09 04:17:45
mybatis 中javaType和OfType 的区别

JavaType和ofType都是用来指定对象类型的,但是JavaType是用来指定pojo中属性的类型,而ofType指定的是映射到list集合属性中pojo的类型。
pojo类:

publicclass User {
    privateint id;
    privateString username;
    privateString mobile;
    privateList<Post>posts;
}
user.xml:
<resultMap type="User" id="resultUserMap">
<result property="id" javaType="int" column="user_id" />
<result property="username" javaType="string" column="username" />
<result property="mobile" column="mobile" />
<!--javatype指定的是user对象的属性的类型(例如id,posts),而oftype指定的是映射到list集合属性中pojo的类型(本例指的是post类型)-->
<collection property="posts" ofType="com.spenglu.Post" javaType="java.util.ArrayList" column="userid">
<id property="id" column="post_id" javaType="int" jdbcType="INTEGER"/>
<result property="title" column="title" javaType="string" jdbcType="VARCHAR"/>
<result property="content" column="content" javaType="string" jdbcType="VARCHAR"/>
</collection>
</resultMap>

---------------------
作者:spenglu
来源:****
原文:https://blog.****.net/u013216156/article/details/78642920
版权声明:本文为博主原创文章,转载请附上博文链接!