1,三级分类树形结构查询
/**
* DDD(Domain-Driven Design): 领域驱动设计
*
* 三级分类树形结构;
* 支持无限层级;
* 当前项目只有三级
*/
@Data
public class CategoryTreeTo {
private Long categoryId; //1
private String categoryName;
private List<CategoryTreeTo> categoryChild;//子分类
}
<!-- 定义Category树形封装规则; 三级固定封装-->
<resultMap id="CategoryTreeRM" type="com.azxc.rapid.modules.main.dto.CategoryTreeTo">
<!-- 一级分类的规则 -->
<id column="id" property="categoryId"></id>
<result column="name" property="categoryName"></result>
<collection property="categoryChild"
ofType="com.azxc.rapid.modules.main.dto.CategoryTreeTo">
<!-- 二级分类封装规则 -->
<id column="c2_id" property="categoryId"></id>
<result column="c2_name" property="categoryName"></result>
<collection property="categoryChild"
ofType="com.azxc.rapid.modules.main.dto.CategoryTreeTo">
<!-- 三级分类封装规则 -->
<id column="c3_id" property="categoryId"></id>
<result column="c3_name" property="categoryName"></result>
</collection>
</collection>
</resultMap>
<select id="getTest" resultMap="CategoryTreeRM">
select bc1.*,
bc2.id c2_id,
bc2.name c2_name,
bc2.category1_id,
bc3.id c3_id,
bc3.name c3_name,
bc3.category2_id
from base_category1 bc1
left join base_category2 bc2 on bc1.id = bc2.category1_id
left join base_category3 bc3 on bc2.id = bc3.category2_id
</select>
执行结果展示</