Mybatis pass parameter List Array

two classes
 
//
public class ShopBean{
private Integer shopId;

private List<BaseBean> shopList;

private String[]  shopArray;

//get  method

//set  method


}

// base class
public  class BaseBean{

private Integer shopId;

private integer shopName;

private String shopAddress;

//get  method

//set  method


}


When the incoming parameter is ShopBean, foreach to access List, you
need to set collection="shopList", which corresponds to the parameter name in ShopBean.
Traverse each BaseBean and set item="item", which can be arbitrary here,
indicating the current BaseBean object being traversed. To access the object in the BaseBean, directly 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>


traverse 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>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326399412&siteId=291194637