mybatis 一对多,嵌套查询

来源:互联网 发布:如涵贸易有哪些淘宝店 编辑:程序博客网 时间:2024/05/16 19:42

商品表product

图片表productImage

一个商品包含多张图片

productMapper:

<select id="getAllProduct" resultMap="getAllProductMap">
SELECT * from product
a,producttype t where
a.productTypeId = t.productTypeId and a.producttypeid=#{producttypeid}
limit #{pageIndex},#{pageSize}
</select>


      <resultMap type="com.chinasoft.model.entity.Product" id="getAllProductMap"
extends="BaseResultMap">
<association property="productType"
javaType="com.chinasoft.model.entity.ProductType">
<id property="producttypeid" column="producttypeid"></id>
<result property="producttypename" column="producttypename"></result>
<result property="producttypeinfo" column="producttypeinfo"></result>
</association>
<collection property="productImageList"
ofType="com.chinasoft.model.entity.ProductImage"  
column="productid"
select="com.chinasoft.model.dao.ProductImageMapper.getImage">
<id property="productimageid" column="productimageid"></id>
<result property="productimageaddress" column="productimageaddress"></result>
<result property="productid" column="productid"></result>
<result property="productimageinfo" column="productimageinfo"></result>
</collection>
</resultMap>


productImageMapper:

<select id="getImage" resultType="com.chinasoft.model.entity.ProductImage" parameterType="Integer"> 
  select * from ProductImage where productid = #{productid} 
 </select>


商品表实体

private Integer productid;

private Integer producttypeid;
private String productname;
private String productnumber;
private String productinfo;
private String producttime;
private Long productprice;
private Integer productcount;
// 一对多,加入商品对应的图片集

private List<ProductImage> productImageList;



0 0
原创粉丝点击