DIshController
java
/**
* 根据id查询菜品,并回显到前端
*
* @param id
* @return
*/
@GetMapping("/{id}")
@ApiOperation("根据id查询菜品")
public Result<DishVO> getById(@PathVariable Long id) {
log.info("根据id查询菜品:{}", id);
DishVO dishVo = dishService.getById(id);
return Result.success(dishVo);
}
DIshService
java
/**
* 根据id查找菜品
*
* @param id
*/
DishVO getById(Long id);
java
/**
* 根据id查询菜品
*
* @param id
* @return
*/
@Override
public DishVO getById(Long id) {
// 根据id查询菜品数据
Dish dish = dishMapper.getById(id);
// 根据菜品id查询其对应的口味数据
List<DishFlavor> dishFlavors = dishFlavorMapper.getByDishId(id);
// 将查询到的数据封装到VO中回显前端
DishVO dishVO = new DishVO();
BeanUtils.copyProperties(dish, dishVO);
dishVO.setFlavors(dishFlavors);
return dishVO;
}
DIshMapper
java
/**
* 根据主键id查询菜品
*
* @param id
* @return
*/
@Select("select * from dish where id = #{id}")
Dish getById(Long id);