Mybatis 传参数 List Array
两个类
// public class ShopBean{ private Integer shopId; private List<BaseBean> shopList; private String[] shopArray; //get method //set method } //基类 public class BaseBean{ private Integer shopId; private Integer shopName; private String shopAddress; //get method //set method }
当传入参数为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 ShopId IN <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 ShopId IN <foreach collection="shopArray" item="item" open="(" separator="," close=")"> #{item} </foreach> </select>
相关推荐
xiuyangsong 2020-11-16
Nishinoshou 2020-11-09
jimgreatly 2020-09-01
dongxurr 2020-08-18
Dullonjiang 2020-08-15
Dullonjiang 2020-08-11
Dullonjiang 2020-08-09
dongxurr 2020-08-08
yunzhonmghe 2020-08-07
jimgreatly 2020-08-03
Dullonjiang 2020-07-30
jimgreatly 2020-07-27
liqiancao 2020-07-26
xiuyangsong 2020-07-26
dongxurr 2020-07-26
mcvsyy 2020-07-26
helloxusir 2020-07-25
牧场SZShepherd 2020-07-20