Java接口命名

规范接口命名是漂亮代码的基础

新建(saveXxx)

    @PostMapping("saveCrh")
    @ApiOperation(value = "创建XX", notes = "创建XX")
    @UserOperationLog(module = "XX管理", operationDesc = "XX车型")
    public ApiResponse save(@RequestBody IasSysCrhModel iasSysCrhModel) {
        try {
            LambdaQueryWrapper<IasSysCrhModel> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(IasSysCrhModel::getName, iasSysCrhModel.getName());
            List<IasSysCrhModel> list = iasSysCrhModelService.list(queryWrapper);
            if (CollectionUtils.isNotEmpty(list)) {
                return ApiResponse.ofWarning("该XX已存在");
            }
            iasSysCrhModelService.save(iasSysCrhModel);
            return ApiResponse.ofSuccess("添加成功");
        } catch (Exception e) {
            log.error("添加XX失败", e);
            return ApiResponse.ofError("添加失败");
        }
    }

修改(updateXxx)

    @PostMapping("updateCrh")
    @ApiOperation(value = "修改XX", notes = "修改XX")
    @UserOperationLog(module = "XX管理", operationDesc = "修改XX")
    public ApiResponse update(@RequestBody IasSysCrhModel iasSysCrhModel) {
        try {
            LambdaQueryWrapper<IasSysCrhModel> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(IasSysCrhModel::getName, iasSysCrhModel.getName());
            queryWrapper.ne(IasSysCrhModel::getId, iasSysCrhModel.getId());
            List<IasSysCrhModel> list = iasSysCrhModelService.list(queryWrapper);
            if (CollectionUtils.isNotEmpty(list)) {
                return ApiResponse.ofWarning("该XX已存在");
            }
            iasSysCrhModelService.updateById(iasSysCrhModel);
            return ApiResponse.ofSuccess("修改成功");
        } catch (Exception e) {
            log.error("修改XX失败", e);
            return ApiResponse.ofError("修改失败");
        }
    }

修改单个(updateXxxById)

查询(selectXxx)

    @ApiOperation("查询所有XX")
    @GetMapping("/selectCrhList")
    public ApiResponse selectCrhList() {
        try {
            return ApiResponse.ofSuccess(iasSysCrhService.getAllCrh());
        } catch (Exception e) {
            log.error("查询XX失败", e);
            return ApiResponse.ofError("查询失败");
        }
    }

查询单个(selectXxxById)

分页查询(xxxByPage)

    @PostMapping("queryByPage")
    @ApiOperation("XX分页查询")
    public ApiResponse queryByPage(@RequestBody IasFaultQuery iasFaultQuery) {
        try {
            return ApiResponse.ofSuccess(iasDumpService.getFaultListByTrain(iasFaultQuery));
        } catch (Exception e) {
            log.error("XX查询错误", e);
            return ApiResponse.ofError("XX查询错误");
        }
    }

删除(delete)

    @GetMapping("delete")
    @ApiOperation(value = "删除字典", notes = "删除字典")
    @UserOperationLog(module = "字典管理", operationDesc = "删除字典")
    public ApiResponse delete(Integer id) {
        try {
            iasSysDictService.removeById(id);
            return ApiResponse.ofSuccess("删除成功");
        } catch (Exception e) {
            log.error("删除字典失败", e);
            return ApiResponse.ofError("删除失败");
        }
    }

删除单个(deleteXxxById)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值