获取树形结构目录:
pojo参数类
public class TargetPackageDir implements Serializable{
private Integer dirId;
private String dirName;
private Integer parentDirId;
private Integer sortNum;
private String dirDescribe;
private String productUuid;
private List<TargetPackageDir> subDir; //子目录
sql table字段
id int
dirname varchar
parent_id
sortnum int
dir_describe
target_package_uuid
返回结果
<resultMap type="com.mpr.mprsp.rms.service.rms.material.pojo.TargetPackageDir" id="treeDir">
<result column="id" property="dirId"/>
<result column="dirname" property="dirName"/>
<result column="sortnum" property="sortNum"/>
<result column="dir_describe" property="dirDescribe"/>
<result column="parent_id" property="parentDirId"/>
<result column="target_package_uuid" property="productUuid"/>
<collection property="subDir" column="id" ofType="TargetPackageDir"
<span style="white-space:pre"> </span>select="getSubTreeDir"/> <!--<span style="font-family: Arial, Helvetica, sans-serif;">property :pojo类子目录属性,column:table字段 ,ofTypoe:子目录的pojo类型 ,select:是查询子目录的的sql Id</span><span style="font-family: Arial, Helvetica, sans-serif;">--></span>
</resultMap>
<select id="queryAllDirByProUUID" parameterType="string" resultMap="treeDir">
select
id,
dirname,
parent_id,
sortnum,
dir_describe,
target_package_uuid
FROM
T_TARGET_PACKAGE_DIR
WHERE
TARGET_PACKAGE_UUID = #{targetPackage_uuid}
and parent_id = 0
</select>
<!-- 一对多查询 -->
<select id="getSubTreeDir" parameterType="string" resultMap="treeDir">
select
id,
dirname,
parent_id,
sortnum,
dir_describe,
target_package_uuid
from t_target_package_dir
where parent_id= #{id}
</select>