根据id查询菜品
This commit is contained in:
parent
a9fdc30d10
commit
821819ed5c
|
@ -5,6 +5,7 @@ import com.sky.dto.DishPageQueryDTO;
|
|||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -61,4 +62,17 @@ public class DishController {
|
|||
dishService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
* @param id Long
|
||||
* @return Result<DishVO>
|
||||
*/
|
||||
@ApiOperation("根据id查询菜品")
|
||||
@GetMapping("/{id}")
|
||||
public Result<DishVO> getBydId(@PathVariable Long id) {
|
||||
log.info("根据id查询菜品:{}",id);
|
||||
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
||||
return Result.success(dishVO);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,11 @@ public interface DishFlavorMapper {
|
|||
* @param dishIds List<Long>
|
||||
*/
|
||||
void deleteByDishIds(List<Long> dishIds);
|
||||
|
||||
/**
|
||||
* 根据菜品id查询口味数据
|
||||
* @param id Long
|
||||
* @return DishFlavor
|
||||
*/
|
||||
List<DishFlavor> getByDishId(Long id);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.sky.service;
|
|||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.DishVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -26,4 +27,11 @@ public interface DishService {
|
|||
* @param ids List<Long>
|
||||
*/
|
||||
void deleteBatch(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
* @param id Long
|
||||
* @return DishVO
|
||||
*/
|
||||
DishVO getByIdWithFlavor(Long id);
|
||||
}
|
||||
|
|
|
@ -97,4 +97,24 @@ public class DishServiceImpl implements DishService {
|
|||
// 删除菜品关联的口味数据
|
||||
dishFlavorMapper.deleteByDishIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
*
|
||||
* @param id Long
|
||||
* @return DishVO
|
||||
*/
|
||||
@Override
|
||||
public DishVO getByIdWithFlavor(Long id) {
|
||||
// 根据id查询菜品数据
|
||||
Dish dish = dishMapper.getById(id);
|
||||
// 根据菜品id查询口味数据
|
||||
List<DishFlavor> flavorList = dishFlavorMapper.getByDishId(id);
|
||||
// 将查询到的菜品数据Vo
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(dish, dishVO);
|
||||
dishVO.setFlavors(flavorList);
|
||||
|
||||
return dishVO;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,11 @@
|
|||
#{dishId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 根据菜品id查询口味数据 -->
|
||||
<select id="getByDishId" resultType="com.sky.entity.DishFlavor">
|
||||
select *
|
||||
from dish_flavor
|
||||
where dish_id = #{dishId};
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue