左连接查询数据 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);
        }

    }
相关推荐
鹿角片ljp3 小时前
LeetCode 64:最小路径和复盘|二维 DP 与 ACM 模式完整写法
java·数据结构·算法
Madison-No73 小时前
搭建项目测试环境
linux·运维·服务器·python
+VX:Fegn08953 小时前
计算机毕业设计|基于springboot + vue蛋糕店管理系统(源码+数据库+文档)
前端·数据库·vue.js·spring boot·课程设计
泡海椒4 小时前
PDF 表格样式优化:jquick-pdf 边框、圆角、背景色
java·开发语言·pdf
悠悠121385 小时前
微服务通信别只看性能:REST 与 gRPC 的 6 个选型判断和一次 502 故障复盘
运维·服务器
Nicander5 小时前
我给 Excalidraw 做了一个本地工作区:DrawSpace
前端·开源
景熙55235 小时前
15.Java 8 Stream 流入门到实战
java·开发语言·数据结构
wno7045 小时前
Spring Security权限控制
java·python·spring
云老大-阿里云国际站代理商6 小时前
华为云国际站服务代理商:NAT网关怎么配?多台ECS共用公网IP要注意什么
服务器·华为云·云计算