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>

相关推荐