使用Mybatis之高级映射collection获取树形结构的数据;
<resultMap type="com.ld.model.firerecruit.vo.EnterInfoVo" id="enterInfo">
//<result column="cityCode" property="cityCode" javaType="java.lang.String" />
//实体类中的属性与数据库中的字段一致时,result标签可以不用写
<collection column="id" property="cvs" ofType="com.ld.model.firerecruit.vo.UserCvVo" javaType="java.util.ArrayList" select="getUserCV"/>
<collection column="id" property="units" ofType="com.ld.model.firerecruit.vo.UserUnitVo" javaType="java.util.ArrayList" select="getUserUnit"/>
</resultMap>
<resultMap type="com.ld.model.firerecruit.vo.UserCvVo" id="userCV"></resultMap>
<resultMap type="com.ld.model.firerecruit.vo.UserUnitVo" id="userUnit"></resultMap>
<select id="getEnterInfoByBatch" parameterType="com.ld.model.common.BaseIdPo"
resultMap="enterInfo">
select
*
from
`t_firerecruit_user_enterinfo`
where
userId = #{userId}
and batch = #{id}
and isDel = 0
</select>
<select id="getUserCV" parameterType="String" resultMap="userCV">
select
*
from
`t_firerecruit_user_cv`
where
enterId = #{id}
and isDel = 0
</select>
<select id="getUserUnit" parameterType="String" resultMap="userUnit">
select
*
from
`t_firerecruit_user_unit`
where
enterId = #{id}
and isDel = 0
</select>
public class EnterInfoVo {
private String id;
private List<UserCvVo> cvs;
private List<UserUnitVo> units;
}