之前说了由Employee找Department,这一节讲一讲由Department找Employee,显然前者是多对一的关系,而后者是一对多的关系。
Department的JavaBean:
private Integer id; |
接口中的方法:
Department getDepByIdPlus(Integer id);
查询的SQL语句:
<select id="getDepByIdPlus" resultMap="Dep"> |
接下来编写resultMap,
collection:定义关联集合类型的属性的封装规则
ofType:指定集合里面的元素类型
<resultMap id="Dep" type="com.figsprite.bean.Department"> |
其实就是一个resultMap套着另外一个resultMap格式的collection
@Test |
原文:https://www.cnblogs.com/figsprite/p/10741469.html