实现树形结构几种方式

 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>

执行结果展示</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有心不在迟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值