十、resultMap 的关联方式实现多表查询(多对一)

<association>用于关联一个对象

  •  property: 指定要关联的属性名
  •  select: 设定要继续引用的查询, namespace+id
  •  column: 查询时需要传递的列

十、resultMap 的关联方式实现多表查询(多对一)

 

 十、resultMap 的关联方式实现多表查询(多对一)

 

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 <mapper namespace="com.mapper.StudentMapper">
 6     <resultMap id="sMap" type="student">
 7         <id property="id" column="sid"/>
 8         <result property="name" column="sname"/>
 9         <result property="age" column="age"/>
10         <result property="gender" column="gender"/>
11         <result property="cid" column="cid"/>
12         <association property="clazz" javaType="clazz">
13             <id property="id" column="cid"/>
14             <result property="name" column="cname"/>
15             <result property="room" column="room"/>
16         </association>
17     </resultMap>
18     <select id="selAll" resultMap="sMap">
19         SELECT
20         s.id sid,s.name sname,s.age,s.gender,c.id cid,c.name cname,c.room
21         from t_student s
22         LEFT JOIN t_class c
23         on s.cid = c.id;
24     </select>
25 </mapper>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-11-27
  • 2021-07-22
  • 2021-08-15
  • 2021-07-07
  • 2021-07-09
猜你喜欢
  • 2021-10-16
  • 2021-12-08
  • 2022-12-23
  • 2021-09-07
  • 2021-09-24
  • 2021-06-11
相关资源
相似解决方案