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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM