/** * 根据菜品ID查找菜品列表 * * @param categoryId 菜品ID * @return 菜品实体列表 */ public List<Dish> getDishesByCategoryId(Long categoryId) { List<Dish> result = new ArrayList<Dish>(); Category category = categoryDao.get(categoryId); if (null != category) { for (Dish dish : category.getDishes()) { // REST服务只获取在售的菜品 if (dish.isOnSell()) { result.add(dish); } } } return result; }
/** * 根据菜品ID查找菜品 * * @param dishId 菜品ID * @return 菜品实体 */ @GET @Path("/{dishId}") @Scope("request") @Produces(MediaType.APPLICATION_JSON) public Map<String, DishVO> getDishById(@PathParam("dishId") Integer dishId) { logger.info("[REST_CALL= getDishById, dishId=" + dishId + "]"); Dish dish = dishService.getDishById(dishId); DishVO dishVO = new DishVO(); if (null != dish) { dishVO.setId(dish.getId()); dishVO.setName(dish.getName()); dishVO.setPicPath(dish.getPicPath()); dishVO.setPrice(dish.getPrice()); dishVO.setOnSell(dish.isOnSell()); } Map<String, DishVO> result = new HashMap<String, DishVO>(); result.put("dish", dishVO); return result; }