Mybatis传递多个不同类型的参数

一、同时传递List和String

实现类

        @Override
	public List fun(String shopId,List list){
	    Map map= new HashMap();
	    map.put("shopId",shopId); 
            map.put("list", list);
            List listCommodity=appCommodityMapper.fun(map);
            return listCommodity;
	}

mapper.xml文件

二、同时传递Bean和String(如果不将String赋值给Bean)

实体类

public class ShoppingCart {
	private String shopId;
	private String commodityId;
	private Integer num;
	public String getShopId() {
		return shopId;
	}
	public void setShopId(String shopId) {
		this.shopId = shopId;
	}
        public String getCommodityId() {
		return commodityId;
	}
	public void setCommodityId(String commodityId) {
		this.commodityId = commodityId;
	}
        public Integer getNum() {
		return num;
	}
	public void setNum(Integer num) {
		this.num = num;
	}
}

实现类

        @Override
	public void fun(Commodity commodity, String customerId) {
		Map map = new HashMap();
		map.put("commodity", commodity);
		map.put("customerId", customerId);
		AppShoppingCartMapper.fun(map);
	}

mapper.xml文件


		INSERT INTO
		shopping_cart(customer_id,shop_id,commodity_id,num,create_time)VALUES
		(
		#{customerId},
		#{commodity.shopId},
		#{commodity.commodityId},
		#{commodity.num},
		NOW()
		)

 

你可能感兴趣的:(Mybatis传递多个参数)