Commit e16c27b6 by 邹磊浩

修改代码

parent bc89217e
...@@ -4,8 +4,10 @@ import java.util.List; ...@@ -4,8 +4,10 @@ import java.util.List;
import java.util.Arrays; import java.util.Arrays;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -42,8 +44,8 @@ public class DepartmentController extends BaseController { ...@@ -42,8 +44,8 @@ public class DepartmentController extends BaseController {
*/ */
@SaCheckPermission("system:department:list") @SaCheckPermission("system:department:list")
@GetMapping("/list") @GetMapping("/list")
public List<DepartmentVo> list(DepartmentBo bo) { public R<List<DepartmentVo>> list(DepartmentBo bo) {
return iDepartmentService.queryPageList(bo); return R.ok(iDepartmentService.queryPageList(bo));
} }
/** /**
...@@ -65,7 +67,7 @@ public class DepartmentController extends BaseController { ...@@ -65,7 +67,7 @@ public class DepartmentController extends BaseController {
@SaCheckPermission("system:department:query") @SaCheckPermission("system:department:query")
@GetMapping("/{id}") @GetMapping("/{id}")
public R<DepartmentVo> getInfo(@NotNull(message = "主键不能为空") public R<DepartmentVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Integer id) { @PathVariable Integer id) {
return R.ok(iDepartmentService.queryById(id)); return R.ok(iDepartmentService.queryById(id));
} }
......
...@@ -47,5 +47,7 @@ public class DepartmentVo { ...@@ -47,5 +47,7 @@ public class DepartmentVo {
private List<DepartmentVo> children; private List<DepartmentVo> children;
private String label;
} }
...@@ -51,12 +51,14 @@ public class DepartmentServiceImpl implements IDepartmentService { ...@@ -51,12 +51,14 @@ public class DepartmentServiceImpl implements IDepartmentService {
//根节点集合 //根节点集合
List<DepartmentVo> rootMenu = new ArrayList<>(); List<DepartmentVo> rootMenu = new ArrayList<>();
for (DepartmentVo entity : allMenu) { for (DepartmentVo entity : allMenu) {
entity.setLabel(entity.getTitle());
if (entity.getParentId() == 0) { //父节点是0的,为根节点。 if (entity.getParentId() == 0) { //父节点是0的,为根节点。
rootMenu.add(entity); rootMenu.add(entity);
} }
} }
//为根菜单设置子菜单,getClild是递归调用的 //为根菜单设置子菜单,getClild是递归调用的
for (DepartmentVo entity : rootMenu) { for (DepartmentVo entity : rootMenu) {
entity.setLabel(entity.getTitle());
/* 获取根节点下的所有子节点 使用getChild方法*/ /* 获取根节点下的所有子节点 使用getChild方法*/
List<DepartmentVo> childList = getChild(entity.getId().toString(), allMenu); List<DepartmentVo> childList = getChild(entity.getId().toString(), allMenu);
entity.setChildren(childList);//给根节点设置子节点 entity.setChildren(childList);//给根节点设置子节点
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment