<resultMapid="nestedCategory"type="com.baizhi.mybatisplus.entity.vo.ProductCategoryVo"><idproperty="id"column="id"/><resultproperty="title"column="title"/><resultproperty="sort"column="sort"/><collectionproperty="children"ofType="com.baizhi.mybatisplus.entity.vo.ProductCategoryVo"select="selectNestedListByParentId"column="id"/></resultMap><selectid="selectNestedListByParentId"resultMap="nestedCategory">
select id,sort,title from tbl_product_category where parent_id = ${parent_id}
</select>
常规写法
@OverridepublicList<ProductCategoryVo>listWithTree(){List<ProductCategory> allMenu = baseMapper.selectList(null);List<ProductCategoryVo> rootMenu =newArrayList<>();for(ProductCategoryVo menu : allMenu){if(menu.getParentId().equals("0")){
rootMenu.add(menu);}}for(ProductCategoryVo nav : rootMenu){List<ProductCategoryVo> childList =getChildren(nav.getId(),allMenu);
nav.setChildren(childList);}return rootMenu;}privateList<ProductCategoryVo>getChildren(String id,List<ProductCategoryVo> allMenu){List<ProductCategoryVo> childList =newArrayList<>();for(ProductCategoryVo nav : allMenu){if(nav.getParentId().equals(id)){
childList.add(nav);}}for(ProductCategoryVo nav : childList){
nav.setChildren(getChildren(nav.getId(),allMenu));}if(childList.size()==0){returnnewArrayList<ProductCategoryVo>();}return childList;}