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

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

获取字典项表单数据接口的实现


获取字典项表单数据接口的需求

根据字典项id 查询字典项


代码实现

在 DeptController 中添加接口

1
2
3
4
5
6
7
8
9
10
11
12
@GetMapping("/{dictCode}/items/{id}/form")
@PreAuthorize("@ps.hasPermission('blog:dict:update')")
@SystemLog(businessName = "获取字典项表单数据接口")
@ApiOperation(value = "获取字典项表单数据接口", notes = "获取字典项表单数据,用于编辑字典项详情", response = DictItemFormDetailVo.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "字典id", dataType = "long", paramType = "path"),
@ApiImplicitParam(name = "dictCode", value = "字典编码", dataType = "string", paramType = "path")
})
public ResponseResult<DictItemFormDetailVo> getDictItemFormDetail(@PathVariable Long id, @PathVariable String dictCode)
{
return sysDictItemService.getDictItemFormDetail(id, dictCode);
}

创建 DictItemFormDetailVo

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

@ApiModelProperty(value = "字典编码", example = "sex")
private String dictCode;

@ApiModelProperty(value = "字典项标签", example = "男")
private String label;

@ApiModelProperty(value = "字典项值", example = "0")
private String value;

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

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

@ApiModelProperty(value = "标签类型,用于前端样式展示(如success、warning等)", example = "success")
private String tagType;
}


在 SysDictItemServiceImpl 中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//获取字典项表单数据
@Override
public ResponseResult<DictItemFormDetailVo> getDictItemFormDetail(Long id, String dictCode)
{
//根据字典项id 查询字典项
SysDictItem dictItem = sysDictItemService.getById(id);
if (dictItem == null) {
return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "该字典项不存在!");
}

//转换成Vo
DictItemFormDetailVo dictItemFormDetailVo = BeanCopyUtils.copyBean(dictItem, DictItemFormDetailVo.class);

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

需要注意的是

为了避免重复代码过多

我将 获取当前用户拥有的数据权限范围 相关的代码提取出来成 applyDeptDataScopeFilter 方法方便调用了

并且在 AdminUserServiceImpl 中也进行了类似的操作




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

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


预告

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

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

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


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


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