自己写的DishService

public List<Dish> getByCategoryId(Long categoryId) {
        List<Dish> list=dishMapper.list(categoryId);
        return list;
    }

自己写的DishMapper

@Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<Dish> list(Long categoryId);

标准答案

public List<Dish> list(Long categoryId) {
    Dish dish = Dish.builder()
        .categoryId(categoryId)
        .status(StatusConstant.ENABLE)
        .build();
    return dishMapper.list(dish);
}
<select id="list" resultType="Dish" parameterType="Dish">
    select * from dish
    <where>
        <if test="name != null">
            and name like concat('%',#{name},'%')
        </if>
        <if test="categoryId != null">
            and category_id = #{categoryId}
        </if>
        <if test="status != null">
            and status = #{status}
        </if>
    </where>
    order by create_time desc
</select>

差别分析:

我满足的需求为:根据分类名称查找在售的菜品
需要的需求为:根据分类名称或菜品名称查找在售的菜品
总结:观察前端页面时,漏了一个根据菜品名称查找菜品的需求,

自己写的SetmealService的存入中间表

//2.在中间表中保存套餐和菜品的关联关系(套餐和菜品是多对多关系
        List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
        setmealDishMapper.insertBatch(setmealDishes);

标准答案

//2.在中间表中保存套餐和菜品的关联关系(套餐和菜品是多对多关系)
        //
        Long setmealId = setmeal.getId();
        List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
        setmealDishes.forEach(setmealDish -> {setmealDish.setSetmealId(setmealId);});
        setmealDishMapper.insertBatch(setmealDishes);

差别分析:

忘记了套餐加入数据库之后才会自增产生id,
所以在套餐保存到数据库之后才能获得套餐的id,并加入中间表中

前端页面未显示

Controller中,注释使用了@Controller,没使用@RestController,没给前端返回信息,当然收不到了

@RequestParam

@RequestParam 注解会将这些 id 收集到一个 List< Long > 中,以便在 deleteBatch(ids) 方法中作为批量删除的参数使用。

Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐