删除套餐(关联表的删除操作,批量删除,单个删除)
生活随笔
收集整理的這篇文章主要介紹了
删除套餐(关联表的删除操作,批量删除,单个删除)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?需求分析:
?代碼開發-梳理交互過程:
?重寫接口:
?
public interface SetmealService extends IService<Setmeal> {/*** 新增套餐,同時需要保存套餐和菜品的關聯* @param setmealDto*/public void saveWithDish(SetmealDto setmealDto);/*** 刪除套餐,同時需要刪除套餐和菜品的關聯數據* @param ids*/public void removeWithDish(List<Long> ids); }?重寫方法:
/*** 刪除套餐,同時需要刪除套餐和菜品的關聯數據* @param ids*/@Overridepublic void removeWithDish(List<Long> ids) {//select count(*) from setmeal where id in(1,2,3) and status = 1;//查詢套餐狀態,確定是否可用刪除LambdaQueryWrapper<Setmeal> eq = Wrappers.lambdaQuery(Setmeal.class).in(Setmeal::getId, ids).eq(Setmeal::getStatus, 1);int count = this.count(eq);if(count > 0){//如果不能刪除,拋出一個業務異常throw new CustomException("套餐正在售賣中,不能刪除");}//如果可以刪除,先刪除套餐表中的數據---setmealthis.removeByIds(ids);//delete from setmeal_dish where setmeal_id in(1,2,3);LambdaQueryWrapper<SetmealDish> in = Wrappers.lambdaQuery(SetmealDish.class).in(SetmealDish::getSetmealId, ids);//刪除關系表中的數據---setmeal_dishsetmealDishService.remove(in);}調用重寫的方法:
/*** 刪除套餐* @param ids* @return*/@DeleteMappingpublic R<String> delete(@RequestParam List<Long> ids){setmealService.removeWithDish(ids);return R.success("套餐數據刪除成功");}總結
以上是生活随笔為你收集整理的删除套餐(关联表的删除操作,批量删除,单个删除)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA编写一个年龄大小判断年纪题
- 下一篇: 我的检讨