网站建设明细价单,微网站 建设,邯郸营销网站建设,免费的简历模板大全MyBatis 的一对多查询可以通过在 resultMap 标签中使用 collection 标签#xff0c;将查询结果映射成 Java 对象的嵌套集合。具体步骤如下#xff1a; 在 resultMap 中使用 collection 标签
在 resultMap 标签中使用 collecti…MyBatis 的一对多查询可以通过在 resultMap 标签中使用 collection 标签将查询结果映射成 Java 对象的嵌套集合。具体步骤如下 在 resultMap 中使用 collection 标签
在 resultMap 标签中使用 collection 标签并指定 property 属性为嵌套集合的属性名column 属性为关联表中的外键列名javaType 属性为嵌套集合中元素的类型。
resultMap idBaseResultMap typecom.example.goods_admin.entity.Goodsid columnid jdbcTypeVARCHAR propertyid /result columnname jdbcTypeVARCHAR propertyname /result columnprice jdbcTypeINTEGER propertyprice /result columnstatus jdbcTypeVARCHAR propertystatus /!-- 嵌套集合 --collection propertyimageUrlList ofTypecom.example.goods_admin.entity.GoodsImgresult propertyimgId columnimgId/result propertygoodsId columngoodsId/result propertyimageName columnimageName/result propertyimageUrl columnimageUrl//collection/resultMap编写 SQL 查询语句
编写 SQL 查询语句使用 JOIN 操作关联两张表 select idselectGoods resultMapBaseResultMap parameterTypecom.example.goods_admin.entity.GoodsSELECTg.id,g.name,g.price,g.status,gi.goodsId ,gi.imageName,gi.imageUrl,gi.imgIdFROMgoods gLEFT JOIN goods_img gi ON g.id gi.goodsIdwhereg.status1if testkeyWord !null and keyWord!and g.name like concat(%, #{keyWord}, %)/ifif testid !null and id!and g.id #{id} and gi.status1/if/where/select 调用查询方法