Mybatis 传参数 List Array
两个类//
public class ShopBean{
private Integer shopId;
private List<BaseBean> shopList;
private String[]shopArray;
//getmethod
//setmethod
}
//基类
publicclass BaseBean{
private Integer shopId;
private Integer shopName;
private String shopAddress;
//getmethod
//setmethod
}
当传入参数为 ShopBean,foreach 访问 List ,
需要设置 collection="shopList",与ShopBean中参数名对应。
遍历每一个 BaseBean ,设置item="item",这里可以任意,
表示遍历的当前BaseBean对象,要访问BaseBean 中的对象 直接item.shopId
<select id="searchMaxSaleProduct" resultType="ShopBean" parameterType="ShopBean" >
SELECT TOP 1
T1.shopId AS ShopId
FROM
dbo.T_Sale T1
WHERE
ShopIdIN
<foreach collection="shopList" item="item" open="(" separator="," close=")">
#{item.shopId}
</foreach>
</select>
遍历 Array
<select id="searchMaxSaleProduct" resultType="ShopBean" parameterType="ShopBean" >
SELECT TOP 1
T1.shopId AS ShopId
FROM
dbo.T_Sale T1
WHERE
ShopIdIN
<foreach collection="shopArray" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
页:
[1]