mybatiscollection
时间: 2023-11-07 13:18:12 浏览: 45
Mybatis中的collection标签用于实现连表查询,其使用场景为1:n和n:n两种情况。在使用collection标签时,需要在类中添加关联集合。collection标签的property属性接受的是集合,用于将下一条SQL的结果映射到该集合中。
与collection不同,association标签的property属性接受的是对象。在使用association标签时,需要指定下一条SQL的入参,并将下一条SQL的结果映射到该对象中。
在TeacherMapper.xml中的代码中,通过resultMap标签定义了一个名为BaseResultMapWithClassInfo的结果映射,其中定义了与teacher表中各个字段的映射关系,并通过collection标签将与teacher表关联的classInfoList集合查询出来。通过select属性指定了执行下一条SQL的位置,通过column属性指定了关联字段,通过select属性指定了查询classInfoList的SQL语句。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Mybaits中collection的用法详解](https://blog.csdn.net/weixin_45001200/article/details/118231169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)