Mapper.xml中的resultMap


1.實體類

 1     class Company{
 2         private String c_id ;
 3         private String c_name ;
 4         private String c_address ;
 5         private String c_type ;
 6         private Dept dept =new Dept();//記得new 不然xml文件會報null
 7         private Role role =new Role();//記得new 不然xml文件會報null
 8         .....
 9     }
10     class Dept{
11         private String d_id ;
12         private String d_name ;
13         private String d_num ;
14         .....
15     }
16     class Role{
17         private String r_id ;
18         private String r_name ;
19         private String r_num ;
20         .....
21     }
22     

 

2.xxMapper.xml中的Map寫法

  <resultMap ik="companyMap" type="com.ss.syf.domain.Company">
                <id column="c_id" property="c_id"/>                 
                <result column="c_name" property="c_name"/>    
                <result column="c_address" property="c_address"/>    
                <result column="c_type" property="c_type"/>       
        <collection property="dept" ofType="com.ss.syf.domain.Dept">
                <id column="d_id" property="d_id"/>
                <result column="d_name" property="d_name"/>
                <result column="d_num" property="d_num"/>
        </collection>
        <collection property="role" ofType="com.ss.syf.domain.Role">
                <id column="r_id" property="r_id"/>
                <result column="r_name" property="r_name"/>
                <result column="r_num" property="r_num"/>
        </collection>
    </resultMap>

 


免責聲明!

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



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