public class A{
private B b1
private List b2
}
在映射b1属性时用association标签, 映射b2时用collection标签,分别是一对一,一对多的关系
把你的条件添加到select语句后面,然后传下去,例如:
<!-- 旅行社详情 --><resultMap type="com.demo.teacher" id="teacherMap">
<id property="teacherId" column="teacher_id"/>
<result property="teacherName" column="teacher_name"/>
<!--注意下面这个声明,只有column-->
<result column="age"/>
<collection property="student" column="{teacherId=teacher_id,age=age}" ofType="java.util.Map" select="studentMap">
<id property="studentId" column="student_id" />
<result property="studentName" column="student_name"/>
<result property="studentAge" column="student_age"/>
</collection>
</resultMap>
<!--主-->
<select id="getTeacher" parameterType="java.util.Map" resultMap="teacherMap">
select
teacher_id,
teacher_name,
#{age} as age <!--把你的参数这样写-->
from
teachers
where
teacher_name = '大西瓜'
</select> <!--从-->
<select id="studentMap" parameterType="java.util.Map" resultType="java.util.Map">
select
student_id,
student_name,
student_age
from
students
where
teacher_id = #{teacherId}
and
age > #{age} <!--这两个参数是resultMap中column指定的key-->
</select>
<!--mybatis的一对多级联查询多方的参数只能是一方的column,所以你要想办法把你的参数做成column-->
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)