在实现菜单查询目前遇到两种方式
1、根据父id依次查询该id为父id的同级菜单,一次查询一个(上下级菜单通过parentId进行关联)
1.1、前台传入参数为父parentId(select * from category where parentId =#{parentId })
①
@GetMapping("/list") public ResponseEntity<List<Category>> queryCategoryByPid(@RequestParam("pid") Long pid) { return ResponseEntity.ok().body(categoryService.list(pid)); }
②
@Override public List<Category> list(Long pid) { final Category category = new Category(); category.setParentId(pid); final List<Category> categories = categoryMapper.select(category); if (CollectionUtils.isEmpty(categories)) { throw new LyException(ExceptionEnum.CATEGORY_ISNULL); } return categories; }
2、通过sql一次全部出来所有菜单
<select id="queryList" resultType="io.renren.modules.sys.entity.SysDeptEntity">
select t1.*,(select t2.name from sys_dept t2 where t2.dept_id=t1.parent_id)parentName from sys_dept t1 where
t1.del_flag = 0
<if test="sql_filter != null">
and ${sql_filter}
</if>
</select>