MyBatis ofType和javaType区别

JavaType和ofType都是用来指定对象类型的,但是JavaType是用来指定pojo中属性的类型,而ofType指定的是 映射到list集合属性中pojo的类型
pojo类:
public class User {
     private int id ;
     private String username ;
     private String mobile ;
     privateListposts;
}

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" />
                       
          < 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 >

你可能感兴趣的:(web)