Mybatis 注解 @Many 实现 递归菜单获取


import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MenuMapper {

@Select("select * from menu where parentid=0")
@Results(id="tree",value = {
@Result(property = "id",column = "id"),
@Result(property = "name",column = "name"),
@Result(property = "parentId",column = "parentId"),
@Result(property = "children",column = "id",many = @Many(select = "getTreeByParentId")),
})
List<Menu> getTreeList();

@Select("select * from menu where parentId = #{parentId}")
@ResultMap("tree")
List<Menu> getTreeByParentId(int parentId);
}
原文地址:https://www.cnblogs.com/BigWrite/p/10997763.html