mybatis一对一关联查询
2021-10-29 本文已影响0人
rainbowz
association的用法
方法1 association中使用select
-
实体类
image.png
-
dao接口
image.png
-
xml
image.png
-
测试类
image.png

可以发现执行了两次sql,我们的用户信息也被打印出来了。
方法2 association中使用resultMap
-
xml
image.png
输出结果

我们在association使用select查询中可以使用left join关联,也可以先查主表,再根据主表的信息查询。比如方式1的sql查询可以修改为

项目代码:https://github.com/rainbowsky911/sb_mybatis
参考文章:https://www.jianshu.com/p/018c0f083501