queryWrapper写内联接,多表查询

LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(Order::getOrderDate, Order::getOrderType,
                    Member::getName, Setmeal::getName)
        .eq(Order::getId, id)
        .eq(Member::getId, Order::getMemberId)
        .eq(Setmeal::getId, Order::getSetmealId);

Map orderMap = orderService
                        .listMaps(queryWrapper)
                        .stream()
                        .findFirst()
                        .orElse(null);

return orderMap;



QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.select("m.name as member", "s.name as setmeal", "o.orderDate", "o.orderType")
        .eq("o.id", id)
        .innerJoin("t_member m", "m.id = o.member_id")
        .innerJoin("t_setmeal s", "s.id = o.setmeal_id");

List> orderMaps = orderService.listMaps(queryWrapper);

// 转换成单个 Map 对象
Map orderMap = orderMaps.stream().findFirst().orElse(null);

return orderMap;

你可能感兴趣的:(java,数据库,mybatis)