iBATIS的一对多关联查询
???? 博客好长时间没有更新技术文章了,今天还是回归一下老本行,给博客带动点更新率,这文章写的关于iBATIS一对多关联查询,觉的iBATIS的一对多关联查询比hibernate 要好处一点。
??1.定义主表的类
????private String breed_id; // 品种关联
????private String file_id; // 图片关联id
????private List breedlist = new ArrayList();
????注意 breedlist 这个变量要和<result property="breedlist" column="id" select="wmf.auth.FlowerQiYe.breedlist"/>要对应
其实关键就在select="wmf.auth.FlowerQiYe.breedlist" 这行代码
2。编写iBATIS配置文件
?? <typeAlias alias="qiyeClass" type="com.dameng.wmf.auth.domain.FlowersQiYe" />
????<typeAlias alias="breedClass" type="com.dameng.wmf.auth.domain.Breed" />
????<resultMap id="qiyeMap" column="id" />
????????<result property="qeyi_name" column="qeyi_name" />
????????<result property="area" column="area" />
????????<result property="phone" column="phone" />
????????<result property="breedlist" column="id" select="wmf.auth.FlowerQiYe.breedlist"/>
????????
????</resultMap>
????<select id="breedlist" resultMap="qiyeMap"
????????parametercellspacing="0" cellpadding="0">
??????<tr>
????????<th style="width:200px;">企业名称</th>
????????<th style="width:350px;">经营品种及价格</th>
????????<th style="width:200px;">地 址</th>
????????<th style="width:230px;">电话联系人</ths>
??????</tr>
??????
?????????????? #foreach($obj in $obj_list.getPage())
??????
??????<tr>
????????<td><a href="#">$!obj.qeyi_name</a></td>
????????<td><div align="left" style="margin-left:10px;">
????????
????#foreach($breed in $!obj.breedlist)
??????????????????<span >品种</span>:$!breed.fare<p>
??????????????<span >
?????????????????? 价格</span>:$!breed.price</span>
??????????????<p>????
????????????<span >特征</span>:$!breed.trait </p>
??????????????#end
??????????????</div>
????????</td>
????????<td>$!obj.area</td>
????????<td>$!obj.phone</td>
??????</tr>
????????#end
????</table>