删除菜品业务代码优化
This commit is contained in:
@@ -23,4 +23,11 @@ public interface DishFlavorMapper {
|
||||
*/
|
||||
@Delete("delete from dish_flavor where dish_id = #{dishId}")
|
||||
void deleteByDishId(Long dishId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据菜品id集合批量删除对应的口味数据
|
||||
* @param dishIds
|
||||
*/
|
||||
void deleteByDishIds(List<Long> dishIds);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DishMapper {
|
||||
|
||||
@@ -53,4 +55,11 @@ public interface DishMapper {
|
||||
*/
|
||||
@Delete("delete from dish where id = #{id}")
|
||||
void deleteById(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 根据菜品id集合批量删除菜品
|
||||
* @param ids
|
||||
*/
|
||||
void deleteByIds(List<Long> ids);
|
||||
}
|
||||
|
||||
@@ -101,12 +101,17 @@ public class DishServiceImpl implements DishService {
|
||||
}
|
||||
|
||||
//删除菜品表中的菜品数据
|
||||
for (Long id : ids) {
|
||||
/* for (Long id : ids) {
|
||||
dishMapper.deleteById(id);
|
||||
//删除菜品关联的口味数据
|
||||
dishFlavorMapper.deleteByDishId(id);
|
||||
}
|
||||
}*/
|
||||
|
||||
//sql:delete from dish where id in (?, ?, ?)
|
||||
|
||||
//根据菜品id集合批量删除菜品数据和关联的口味数据
|
||||
dishMapper.deleteByIds(ids);
|
||||
dishFlavorMapper.deleteByDishIds(ids);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user