多条数据增加,删除

博客主要介绍了使用MyBatis实现数据操作,包括多条数据的新增和删除,涉及action、Service、ServiceImpl、Mapper等方面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

多条增加:
action:

//grtValueRevaluation为前端传的多条数据,是个集合
public Result addGrtValueRevaluation(Context context) {
//这里用getData获取的集合里面是LinkedHashMap类型
       List grtValueRevaluation = (List) context.getData("grtValueRevaluation");
//        List<GrtValueRevaluationInfo> grtValueRevaluation = JSON.parseArray(context.getString("grtValueRevaluation"), GrtValueRevaluationInfo.class);
        if (grtValueRevaluation != null && grtValueRevaluation.size() > 0) {

            ArrayList<GrtValueRevaluationInfo> grtValueRevaluationInfos = new ArrayList<>();
             //这里生成批次号
            String batNo = grtBatchNumberUtil.getSequence("GRT_BATCH_NO");
            for (int i = 0; i < grtValueRevaluation.size(); i++) {
                GrtValueRevaluationInfo grtValueRevaluationInfo = new GrtValueRevaluationInfo();
//这里获取必须是LinkedHashMap 
                LinkedHashMap map = (LinkedHashMap) grtValueRevaluation.get(i);
                grtValueRevaluationInfo.setId(idGenerator.nextIdStr());
                grtValueRevaluationInfo.setGuarantyNo(map.get("guarantyNo").toString());
                grtValueRevaluationInfo.setGuanCustName(map.get("guanCustName").toString());
                grtValueRevaluationInfo.setGuanCustNo(map.get("guanCustNo").toString());
                grtValueRevaluationInfo.setCollateralAddress(map.get("guanName").toString());
                grtValueRevaluationInfo.setLastTimeTotal(new BigDecimal(map.get("finalTotal").toString()));
                GrtValueInfo grtValueInfo = grtValueInfoService.selectByGuarantyNo(map.get("guarantyNo").toString());
                grtValueRevaluationInfo.setSystemTotal(grtValueInfo.getSystemTotal());
                grtValueRevaluationInfo.setSystemDate(grtValueInfo.getSystemDate());
                grtValueRevaluationInfo.setSfRg(grtValueInfo.getSfRg());
                grtValueRevaluationInfo.setRgTotal(grtValueInfo.getRgTotal());
                grtValueRevaluationInfo.setRgDate(grtValueInfo.getRgAssessDate());
                grtValueRevaluationInfo.setRevaluationType(DictConstant.REVALUATION_STATE_1);
                MortgageRealEstate mortgageRealEstate = mortgageRealEstateService.selectByGuarantyNo(map.get("guarantyNo").toString());
                grtValueRevaluationInfo.setArea(mortgageRealEstate.getBuiledArea().toString());
                grtValueRevaluationInfo.setBatchNumber(batNo);
                grtValueRevaluationInfos.add(grtValueRevaluationInfo);
            }
            grtValueRevaluationInfoService.insertBatchInfo(grtValueRevaluationInfos);
        }
        return Result.success("新增成功");
    }

Service:

   void insertBatchInfo(List<GrtValueRevaluationInfo> list);

ServiceImpl :

@Override
    public void insertBatchInfo(List<GrtValueRevaluationInfo> list) {
        if (list != null && list.size() > 0) {
            grtValueRevaluationInfoExtMapper.insertBatchInfo(list);
        }
    }

Mapper :

 int insertBatchInfo(@Param("paramList") List<GrtValueRevaluationInfo> list);

mybatis实现多条数据新增

 <insert id="insertBatchInfo" parameterType="java.util.List">
        insert into grt_value_revaluation_info (id, guaranty_no, glb_serial_no, batch_number, collateral_address, guan_cust_no,
        guan_cust_name, last_time_total, system_total, system_date, sf_rg, area, rg_total,
        rg_date, new_final_total, new_final_date, revaluation_type, create_user, create_org,
        create_time, update_user, update_org, update_time, cur_vers)
        values
        <foreach collection="paramList" item="item" index="index" separator=",">
            (#{item.id,jdbcType=VARCHAR}, #{item.guarantyNo,jdbcType=VARCHAR},#{item.glbSerialNo,jdbcType=VARCHAR},
            #{item.batchNumber,jdbcType=VARCHAR},#{item.collateralAddress,jdbcType=VARCHAR},
            #{item.guanCustNo,jdbcType=VARCHAR},#{item.guanCustName,jdbcType=VARCHAR},
            #{item.lastTimeTotal,jdbcType=DECIMAL},#{item.systemTotal,jdbcType=DECIMAL},
            #{item.systemDate,jdbcType=VARCHAR},#{item.sfRg,jdbcType=VARCHAR},#{item.area,jdbcType=VARCHAR},
            #{item.rgTotal,jdbcType=DECIMAL},#{item.rgDate,jdbcType=VARCHAR},#{item.newFinalTotal,jdbcType=DECIMAL},
            #{item.newFinalDate,jdbcType=VARCHAR},#{item.revaluationType,jdbcType=VARCHAR},#{item.createUser,jdbcType=VARCHAR},
            #{item.createOrg,jdbcType=VARCHAR},#{item.createTime,jdbcType=VARCHAR},#{item.updateUser,jdbcType=VARCHAR},
            #{item.updateOrg,jdbcType=VARCHAR},#{item.updateTime,jdbcType=VARCHAR},#{item.curVers,jdbcType=VARCHAR})
        </foreach>
    </insert>

mybatis实现多条数据删除:

<delete id="deleteGrtValueRevaluation" parameterType="java.util.List">
        DELETE FROM grt_value_revaluation_info
        WHERE id in (
            <foreach collection="paramList" item="item" index="index" separator=",">
                #{item.id,jdbcType=VARCHAR}
            </foreach>
        )
    </delete>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值