返回类结构(内部类)
public class testDto{
private Integer id;
private String name;
private List<Child> childList;
public static class Child{
private Integer id;
private String name;
}
}
resultMap编写
<resultMap id="TestDto" type="com.x.y.testDto">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<association property="childList" column="id" select="queryChildList" javaType="java.util.ArrayList" />
</resultMap>
‘select’为嵌套查询的SQL的ID名称
‘column’为要带入的某列的值
<select id="queryTestDto" resultMap="TestDto">
SELECT id,name FROM test
</select>
<select id="queryTestDto" resultMap="com.x.y.testDto$Child">
SELECT id,name FROM test
WHERE parent_id=#{id}
</select>