colleciton 标签
Mybatis的 collection 是一对多的使用的, 在 resultMap 标签内使用
当一个Bean中有 一个list属性需要关联查询出来的使用就用collection 标签
我这里用省,市两表来做演示
(我用mybatis-plus生成的表)
!['图片title' alt text](https://images.shenmazong.com/blog/a96ba70b-4cec-4e3c-a46c-69ba9cb71008.png)
!['图片title' alt text](https://images.shenmazong.com/blog/3543227a-1da8-404a-935b-6d87fb91ccd5.png)
具体xml文件
!['图片title' alt text](https://images.shenmazong.com/blog/efbcb58c-d5c5-4aca-b297-c4e012191471.png)
效果
!['图片title' alt text](https://images.shenmazong.com/blog/60d6c6fe-12cd-45b2-ac13-42b2de07a714.png)
小知识:
- jdbcType是数据库数据类型
- JavaType是用来指定pojo中对象属性的类型
- ofType指定的是映射到list集合属性中泛型的类型
- column对应sql中的列名
- property对应pojo中的属性名,也就是说property是column的别名