删除菜品业务代码优化
This commit is contained in:
@@ -23,4 +23,11 @@ public interface DishFlavorMapper {
|
|||||||
*/
|
*/
|
||||||
@Delete("delete from dish_flavor where dish_id = #{dishId}")
|
@Delete("delete from dish_flavor where dish_id = #{dishId}")
|
||||||
void deleteByDishId(Long 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.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DishMapper {
|
public interface DishMapper {
|
||||||
|
|
||||||
@@ -53,4 +55,11 @@ public interface DishMapper {
|
|||||||
*/
|
*/
|
||||||
@Delete("delete from dish where id = #{id}")
|
@Delete("delete from dish where id = #{id}")
|
||||||
void deleteById(Long 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);
|
dishMapper.deleteById(id);
|
||||||
//删除菜品关联的口味数据
|
//删除菜品关联的口味数据
|
||||||
dishFlavorMapper.deleteByDishId(id);
|
dishFlavorMapper.deleteByDishId(id);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
//sql:delete from dish where id in (?, ?, ?)
|
||||||
|
|
||||||
|
//根据菜品id集合批量删除菜品数据和关联的口味数据
|
||||||
|
dishMapper.deleteByIds(ids);
|
||||||
|
dishFlavorMapper.deleteByDishIds(ids);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,11 @@
|
|||||||
(#{df.dishId}, #{df.name}, #{df.value} )
|
(#{df.dishId}, #{df.name}, #{df.value} )
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<delete id="deleteByDishIds">
|
||||||
|
delete from dish_flavor where dish_id in
|
||||||
|
<foreach collection="dishIds" item="dishId" separator="," open="(" close=")">
|
||||||
|
#{dishId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
@@ -11,6 +11,14 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
|
<delete id="deleteByIds">
|
||||||
|
delete from dish where id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
|
||||||
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||||
select d.*, c.name as categoryName from dish d left outer join category c on d.category_id = c.id
|
select d.*, c.name as categoryName from dish d left outer join category c on d.category_id = c.id
|
||||||
<where>
|
<where>
|
||||||
|
|||||||
Reference in New Issue
Block a user