类:
public class EnumOption
{
private String value;
private String label;
private List<EnumOption> children;
}
mapper实现父子层级关系图:
<resultMap id="enumOptionResultMap" type="dto.EnumOption">
<id column="parentRegionId" property="value"/>
<result column="parentRegionName" property="label"/>
<collection property="children" ofType="dto.EnumOption">
<id column="regionId" property="value"/>
<result column="regionName" property="label"/>
</collection>
</resultMap>
<!-- 获取地区列表 -->
<select id="getList" resultMap="enumOptionResultMap">
SELECT
t1.id parentRegionId,
t1.name parentRegionName,
t2.id regionId,
t2.name regionName
FROM
base_table t1
JOIN base_table t2 ON t1.id = t2.parent_id
WHERE
t1.parent_id = '0000'
ORDER BY
t1.CODE DESC,
t2.id
</select>