左连接查询数据 left join

同理的Right

XML 复制代码
<select id="pageQuery" resultType="com.sky.vo.DishVO">
        select d.* , c.name as categoryName from dish d left outer join category c on d.category_id = c.id
        <where>
            <if test="name != null">
                and d.name like concat('%',#{name},'%')
            </if>
            <if test="categoryId != null">
                and d.category_id = #{categoryId}
            </if>
            <if test="status != null">
                and d.status = #{status}
            </if>
        </where>
        order by d.create_time desc
    </select>

事务机制,要么同时成功,要么同时失败

java 复制代码
    //新增菜品
    @Override
    @Transactional
    public void saveWithFlavor(DishDTO dishDTO) {

        // 新增表菜品
        Dish dish = new Dish();
        BeanUtils.copyProperties(dishDTO,dish);
        dish.setImage("目前没有阿里云服务器OOS,先这样了..");
        dishMapper.insert(dish);
        Long dishId = dish.getId();// 获取到生成的ID,然后赋值到 dish_flavor这个表里面

        //新增口味,批量循环添加口味
        List<DishFlavor> flavors = dishDTO.getFlavors();
        if(!flavors.isEmpty() && flavors != null){

            // 设置dish_flavor表的菜单ID值
            flavors.forEach((item)->{
                item.setDishId(dishId);
            });

            //向口味表插入n条数据
            dishFlavorMapper.insertBatch(flavors);
        }

    }
相关推荐
这个昵称不容易6 分钟前
SpringBoot 购物推荐网站的设计与实现:120 个 Java 文件、147 个接口、13 张表,附真实运行截图
java·springboot·毕设
文丑颜不良啊12 分钟前
LeetCode3041~3060题目解析
java·leetcode
文丑颜不良啊2 小时前
LeetCode3101~3120题目解析
java·leetcode
Resean02232 小时前
SpringMVC 6+源码分析(十一)视图渲染与异步请求(收尾篇)
java·spring·springmvc
靠沿2 小时前
MySQL数据库进阶——存储过程和触发器
java·数据库·mysql
IT_陈寒3 小时前
Redis那个过期删除策略,差点让我线上崩了
前端·人工智能·后端
jianqiang.xue3 小时前
Espressif-IDE进入维护模式:乐鑫把ESP32开发的宝押给VS Code
前端·css·ide
码少女3 小时前
MySQL--库与表的增删改查基础
java·数据库·mysql
Eyfcom3 小时前
〖物流 SaaS 实战 02〗SaaS 租户的计费与订阅模型:从“一锤子买卖”到“按需订阅”
linux·服务器·数据库·快递系统·物流saas实战
特创数字科技3 小时前
纯本地离线运行的文档脱敏工具(技术分享)
前端·驱动开发·python