mapper接口层:
需注意:入参:@Param(value = “customer”)
package com.itheima.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface CustomerMapper{
//保存:用户数据入库
void saveCustomerData(@Param(value = "customer") Map<String, Object> map);
}
Mapper.xml层:
<!-- 保存:用户数据入库(通过Map循环插入) -->
<!-- 需注意:Map中的key在数据库表中必须存在 -->
<insert id="saveCustomerData" parameterType="map">
INSERT IGNORE INTO customer_data
<if test = "null != customer and customer.size > 0">
<foreach collection="customer.entrySet()" index="key" separator="," open="(" close=")">
${key}
</foreach>
VALUES
<foreach collection="customer.entrySet()" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</if>
</insert>