Mybatis insert into 参数类型parameterType为List

Mybatis 插入记录时,传入的参数类型是List (可以对比下一篇文章 传入的参数类型是hashmap, 而且hashmap里面包含List)

1. DAO

int insertListContacts(List record);

2. Mapper.xml

注意: 里面不能有open="(" close=")"


        insert into t_org_contact ( Forg_id, Fcontact_type, Fcontact_name,Fcontact_mobile,Fcontact_email,
        Fproduct, Fcontract_num )
        values
        
            (#{item.orgId,jdbcType=BIGINT},
            #{item.contactType,jdbcType=BIGINT},
            #{item.contactName,jdbcType=VARCHAR},
            #{item.contactMobile,jdbcType=VARCHAR},
            #{item.contactEmail,jdbcType=VARCHAR},
            #{item.product,jdbcType=VARCHAR},
            #{item.contractNum,jdbcType=VARCHAR} )
        
    

3. ServiceImpl

 private void insertOrgContact(Long orgId, AbstractOrganizationInfoParam param) {
        List listBuz = new ArrayList<>();
        List listOpe = new ArrayList<>();

        //业务联系人       
       for (OrganizationContactInfoParam organizationContactInfoParam : param.getBuzContactInfo()) {
            OrgContact orgContact = new OrgContact(organizationContactInfoParam);
            orgContact.setOrgId(orgId);
            orgContact.setContactType(ContactTypeEnum.businiss.getCode());
            listBuz.add(orgContact);
        }
        if (CollectionUtils.isNotEmpty(listBuz)) {
            orgContactMapper.insertListContacts(listBuz);
        }
        //运营联系人
        for (OrganizationContactInfoParam organizationContactInfoParam : param.getOpeContactInfo()) {
            OrgContact orgContact = new OrgContact(organizationContactInfoParam);
            orgContact.setOrgId(orgId);
            orgContact.setContactType(ContactTypeEnum.operation.getCode());
            listOpe.add(orgContact);
        }
        if (CollectionUtils.isNotEmpty(listOpe)) {
            orgContactMapper.insertListContacts(listOpe);
        }
    }

 

Mybatis insert into 参数类型parameterType为hashmap,hashmap里面含有List: https://blog.csdn.net/qb170217/article/details/81315955

 

你可能感兴趣的:(mybatis)