本文最后更新于 2026年5月24日 下午
获取字典表单数据接口的实现
获取字典表单数据接口的需求
获取字典id
封装为Vo返回
代码实现
DictController
1 2 3 4 5 6 7 8 9 10 11
| @GetMapping("/{id}/form") @PreAuthorize("@ps.hasPermission('blog:dict:update')") @SystemLog(businessName = "获取字典表单数据接口") @ApiOperation(value = "获取字典表单数据接口", notes = "获取字典表单数据,用于编辑字典详情", response = DictFormDetailVo.class) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "字典id", dataType = "long", paramType = "path") }) public ResponseResult<DictFormDetailVo> getDictFormDetail(@PathVariable Long id) { return sysDictService.getDictFormDetail(id); }
|
创建 DictFormDetailVo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| @Data @AllArgsConstructor @NoArgsConstructor @ApiModel(description = "字典表单详情响应对象") public class DictFormDetailVo { @ApiModelProperty(value = "字典ID", example = "1") private Long id;
@ApiModelProperty(value = "字典名", example = "性别") private String name;
@ApiModelProperty(value = "字典编码", example = "sex") private String dictCode;
@ApiModelProperty(value = "状态(0-正常,1-禁用)", example = "0") private String status;
@ApiModelProperty(value = "备注", example = "这里是字典备注") private String remark; }
|
在 SysDictServiceImpl 中实现功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @Override public ResponseResult<DictFormDetailVo> getDictFormDetail(Long id) { SysDict dict = sysDictService.getById(id); if (dict == null) { return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR, "该字典不存在!"); }
DictFormDetailVo dictFormDetailVo = BeanCopyUtils.copyBean(dict, DictFormDetailVo.class);
return ResponseResult.okResult(dictFormDetailVo); }
|
PS:该系列只做为作者学习开发项目做的笔记用
不一定符合读者来学习,仅供参考
预告
后续会记录博客的开发过程
每次学习会做一份笔记来进行发表
“一花一世界,一叶一菩提”
版权所有 © 2026 云梦泽
欢迎访问我的个人网站:https://hgt12.github.io/