mybaitis plus 多表联合查询并举例
时间: 2024-01-17 15:05:30 浏览: 67
MyBatis-Plus多表联合查询并且分页(3表联合)
5星 · 资源好评率100%
好的,对于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来实现多表联合查询了。
阅读全文