『博客开发日记-后台』之获取部门表单数据接口的实现

本文最后更新于 2026年5月22日 晚上

获取部门表单数据接口的实现


获取部门表单数据接口的需求

获取部门id

封装为Vo返回


代码实现

DeptController

1
2
3
4
5
6
7
8
9
 @GetMapping("/{id}/form")
@PreAuthorize("@ps.hasPermission('blog:dept:update')")
@SystemLog(businessName = "获取部门表单数据接口")
@ApiOperation(value = "获取部门表单数据接口", notes = "获取部门表单数据,用于编辑部门详情", response = DeptFormDetailVo.class)
@ApiImplicitParam(name = "id", value = "部门id", dataType = "long", paramType = "path")
public ResponseResult<DeptFormDetailVo> getDeptFormDetail(@PathVariable Long id)
{
return sysDeptService.getDeptFormDetail(id);
}

创建 DeptFormDetailVo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "部门表单详情响应对象")
public class DeptFormDetailVo
{
@ApiModelProperty(value = "部门ID", example = "1")
private Long id;

@ApiModelProperty(value = "部门名称", example = "步步部")
private String name;

@ApiModelProperty(value = "部门编号", example = "ROOT")
private String code;

@ApiModelProperty(value = "父部门ID", example = "1")
private Long parentId;

@ApiModelProperty(value = "状态(0-正常,1-禁用)", example = "0")
private String status;

@ApiModelProperty(value = "排序", example = "1")
private Integer sort;
}

在 SysDeptServiceImpl 中实现功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
     @Autowired
private SysDeptService sysDeptService;

//获取部门表单详情
@Override
public ResponseResult<DeptFormDetailVo> getDeptFormDetail(Long id)
{
//获取部门id
SysDept dept = sysDeptService.getById(id);
if (dept == null) {
return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "该部门不存在!");
}

//封装为Vo
DeptFormDetailVo deptFormDetailVo = BeanCopyUtils.copyBean(dept, DeptFormDetailVo.class);

//返回
return ResponseResult.okResult(deptFormDetailVo);
}



PS:该系列只做为作者学习开发项目做的笔记用

不一定符合读者来学习,仅供参考


预告

后续会记录博客的开发过程

每次学习会做一份笔记来进行发表

“一花一世界,一叶一菩提”


版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/


『博客开发日记-后台』之获取部门表单数据接口的实现
http://example.com/2026/05/22/『博客开发日记-后台』之获取部门表单数据接口的实现/
作者
云梦泽
发布于
2026年5月22日
更新于
2026年5月22日
许可协议