瑞吉外卖项目实战---菜品管理的功能补全篇
-
菜品单独启售停售和批量启售停售(管理端)
package com.itheima.reggie.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.itheima.reggie.comment.R; import com.itheima.reggie.dto.DishDto; import com.itheima.reggie.entity.Category; import com.itheima.reggie.entity.Dish; import com.itheima.reggie.service.CategoryService; import com.itheima.reggie.service.DishFlavorService; import com.itheima.reggie.service.DishService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.stream.Collectors; /** * 菜品管理 */ @RestController @RequestMapping("/dish") @Slf4j public class DishController { @Autowired private DishService dishService; /** * 停售与启用 * @param ids * @return */ @PostMapping("/status/0") public R<String> update1(long[] ids){ // log.info(String.valueOf(ids)); for (long id : ids) { Dish dish = new Dish(); dish.setId(id); dish.setStatus(0); dishService.updateById(dish); } return R.success("修改成功"); } @PostMapping("/status/1") public R<String> update2(long[] ids){ // log.info(String.valueOf(ids)); for (long id : ids) { Dish dish = new Dish(); dish.setId(id); dish.setStatus(1); dishService.updateById(dish); } return R.success("修改成功"); }
-
菜品删除和批量删除(管理端)
package com.itheima.reggie.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.itheima.reggie.comment.R; import com.itheima.reggie.dto.DishDto; import com.itheima.reggie.entity.Category; import com.itheima.reggie.entity.Dish; import com.itheima.reggie.service.CategoryService; import com.itheima.reggie.service.DishFlavorService; import com.itheima.reggie.service.DishService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.stream.Collectors; /** * 菜品管理 */ @RestController @RequestMapping("/dish") @Slf4j public class DishController { @Autowired private DishService dishService; /** * 菜品删除功能 * @param ids * @return */ @DeleteMapping public R<String> delete(long[] ids){ // log.info(String.valueOf(ids)); for (long id : ids) { dishService.removeById(id); } return R.success("删除成功"); } }
重点:就是要用数组在接受前端发送的数据,遍历执行就行。
下一篇:
JAVA面向对象之箭头函数