/**
* 根据主键查询菜品
* @param id
* @return
*/@Select("select * from dish where id = #{id}")DishgetById(Long id);
根据id删除菜品表中的菜品
/**
* 根据主键(id)删除菜品表中的菜品
* @param id
*/@Delete("delete from dish where id = #{id}")voiddeleteById(Long id);
setmealDishMapper
判断当前菜品是否能够删除 – 是否被套餐关联
setmeal_dish表,根据菜品id(dish_id)查
/**
* 根据菜品id查询对应的套餐id
* @param dishIds
* @return
*/// select setmeal_id from setmeal_dish where dish_id in (1, 2, 3, 4)List<Long>getSetmealIdsByDishIds(List<Long> dishIds);
<selectid="getSetmealIdsByDishIds"resultType="java.lang.Long">
select setmeal_id from setmeal_dish where dish_id in
<foreachcollection="dishIds"item="dishId"separator=","open="("close=")">
#{dishId}
</foreach></select>
dishFlavorMapper
删除菜品关联的口味数据 – 不用查有没有,根据菜品id尝试去删就行了
/**
* 根据菜品id删除口味
* @param dishId
*/@Delete("delete from dish_flavor where dish_id = #{dishId}")voiddeleteByDishId(Long dishId);
改进
// 根据菜品id集合批量删除菜品数据// delete from dish where id in (?, ?)
dishMapper.deleteByIds(ids);// 根据菜品id集合批量删除关联的口味数据// delete from dish_flavor where id in (?, ?)
dishFlavorMapper.deleteByDishIds(ids);
<deleteid="deleteByDishIds">
delete from dish_flavor where dish_id in
<foreachcollection="dishIds"open="("close=")"separator=","item="dishId">
#{dishId}
</foreach></delete>