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);
}
posted @ 2019-06-10 15:08  BigWrite  阅读(3583)  评论(0编辑  收藏  举报