增删改增删改

 save@PostMapping("/save")
    public ResponseResult save(@RequestBody ChannelDto channelDto){
//        参数判断
        if(channelDto == null || StringUtils.isBlank(channelDto.getName())){
            return ResponseResult.error(AppHttpCodeEnum.PARAM_REQUIRE);
        }
//        对象转换
        AdChannel adChannel = BeanHelper.copyProperties(channelDto, AdChannel.class);
        boolean b = channelService.save(adChannel);
        if(!b){
            throw new LeadException(AppHttpCodeEnum.SERVER_ERROR);
        }
        return ResponseResult.ok();
    }

修改

@PutMapping("/update")
    public ResponseResult update(@RequestBody ChannelDto channelDto){
//        参数判断
        if(channelDto == null || channelDto.getId() == null){
            return ResponseResult.error(AppHttpCodeEnum.PARAM_REQUIRE);
        }
//        对象转换
        AdChannel adChannel = BeanHelper.copyProperties(channelDto, AdChannel.class);
        boolean b = channelService.updateById(adChannel);
        if(!b){
            throw new LeadException(AppHttpCodeEnum.SERVER_ERROR);
        }
        return ResponseResult.ok();
    }

如果当前状态为有效则不能删除

 根据id 删除  void delete(Long id);

@Override
    public void delete(Long id) {
        AdChannel adChannel = this.getById(id);
        if(adChannel == null){
            throw new LeadException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        if(adChannel.getStatus()){
            throw new LeadException(AppHttpCodeEnum.PARAM_INVALID,"只有在无效状态才能删除");
        }
        boolean b = this.removeById(id);
        if(!b){
            throw new LeadException(AppHttpCodeEnum.SERVER_ERROR,"删除失败!");
        }
    }

@DeleteMapping("/del/{id}")
public ResponseResult deleteById(@PathVariable("id") Long id){
    channelService.delete(id);
    return ResponseResult.ok();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值