springboot——Mapper.xml中的resultMap


1.实体类

复制代码
 1     class Company{  2 private String c_id ; //对应数据库中的PKEY  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 ; //对应数据库中的PKEY 12 private String d_name ; 13 private String d_num ; 14  ..... 15  } 16 class Role{ 17 private String r_id ; //对应数据库中的PKEY 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