mybatis. Parameter 'xxxList' not found. Available parameters are [c

今天遇到遇到一个myabitis 批量Insert时报出的
Parameter ‘promotionActivityRuleList’ not found. Available parameters are [collection, list]

org.apache.ibatis.binding.BindingException: Parameter 'List' not found. Available parameters are [collection, list]

测试代码:

 @Test
    public void  testAddRule(){
        RulePlatformDto rulePlatformDto  = new RulePlatformDto();
        rulePlatformDto.setActivityId(2);
        rulePlatformDto.setActivityType(1);
        rulePlatformDto.setResidueStock(100);
        rulePlatformDto.setExtendJson("{'name':'android ios java'}");
        rulePlatformDto.setC_t(2323113);
        rulePlatformDto.setU_t(123231);
        rulePlatformDto.setCreateId(23);
        rulePlatformDto.setCreateName("21");
        rulePlatformDto.setUpdateId(12);
        rulePlatformDto.setUpdateName("meicai");
        rulePlatformDto.setC_t(231);
        rulePlatformDto.setU_t(213);
        rulePlatformDto.setCreateId(777);
        rulePlatformDto.setIs_deleted(0);
        List list = new ArrayList<>();
        list.add(rulePlatformDto);
        BaseResultPlatformDto  booleanBaseResultPlatformDto=  rulePlatformApi.addPromotionActivityRule(list);
        LogUtils.e(booleanBaseResultPlatformDto.toString());
    }

Dao 文件:

 int batchInsert(List promotionRuleList);

Mapper文件:


 
        INSERT INTO t_promotion_rule
        (id, f_activity_id, activity_type, residue_stock, extend_json, create_id, create_name, update_id, update_name, c_t, u_t, is_deleted)
        VALUES
        
            (#{item.id},
            #{item.factivityId},
            #{item.activityType},
            #{item.residueStock},
            #{item.extendJson},
            #{item.createId},
            #{item.createName},
            #{item.updateId},
            #{item.updateName},
            UNIX_TIMESTAMP(),
            UNIX_TIMESTAMP(),
            0)
        
    

mybatis 文档描述的是List 将会被转为Map, 这里我转入collection=”promotionRuleList” 将被转换成
Map<”list”: promotionRuleList>
http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#Parameters

收集了两种解决方案:

方案一:

collection="promotionRuleList" 改写为 collection="list"

方案二:

在Dao层将参数封装到Map数据结构中
在mapper.xml 使collection="map"

你可能感兴趣的:(电商,JavaEE)