前提:Teacher(integer id,String name,List<Student> students);
<resultMap>
<collection property="students" resultMap="StudentMapper.StudentResultMap" />
</resultMap>
<!-- StudengResultMap 在 StudentMapper 包中 -->
<select id="findTeacherById" parameterType="int" resultMap="TeacherResultMap" >
select tt.id as t_id,
tt.name as t_name,
ts.id as s_id,
ts.name as s_name,
ts.supervisor_id as s_supervisor_id
from t_teacher tt left outer join t_student ts
on tt.id = ts.supervisor_id
where tt.id=#{id}
</select>
mybatis的collection用法,表示has-many
猜你喜欢
转载自kisaii.iteye.com/blog/2018019
今日推荐
周排行