mybaitis plus 多表联合查询并举例
时间: 2024-01-17 19:05:30 浏览: 70
好的,对于mybatis plus多表联合查询,你可以使用@Join注解来实现,具体可以参考以下代码示例:
```java
@TableName("user")
public class User {
@TableId
private Long id;
private String name;
private Integer age;
private String email;
}
@TableName("order")
public class Order {
@TableId
private Long id;
private String orderNo;
private Long userId;
}
@Data
public class UserOrder {
private Long userId;
private String name;
private String email;
private List<Order> orderList;
}
public interface UserMapper extends BaseMapper<User> {
@Select("select u.id as userId, u.name, u.email, o.id as orderId, o.order_no from user u " +
"left join order o on u.id = o.user_id " +
"where u.id = #{userId}")
List<UserOrder> selectUserOrders(@Param("userId") Long userId);
}
```
这样,你就可以使用mybatis plus来实现多表联合查询了。
阅读全文