mybatis注解批量插入、更新

本文探讨了在数据库管理中,如何通过使用批量插入和批量更新的方式提高入库速度。示例展示了使用注解@Insert和@Update进行SQL脚本的批量操作,从而大幅提升数据处理的效率,适用于大量数据的入库和更新场景。

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

需求

在进行入库时,数据一条条入库时间太慢了,批量入库速度更快

批量插入

这里使用注解的方法@Insert进行数据插入

@Insert("<script>  " +
            "insert into communityinfo (tguid,CityName,District,ResidentialAreaName,ResidentialAreaAlias,School,Description,NearbySchool,SupportFacility,RingRoad,ManagementCompany,GreeningRate,ManagementFees,ManagementFeesDesp,BaseFacility,Network,PublicSecurity,CarsAmount,ParkingRatio,Parking,BuildingCategory,HouseTypes,HouseType,EndJobDate,CompletionDate,SellDate,LandUseYearsLimit,DeveloperCompany,BuildingStructure,BuildingArea,LandArea,HousingCount,HouseBuildingCount,FloorAreaRatio) VALUES " +
            "<foreach collection=\"list\" item=\"community\" index=\"index\"  separator=\",\"> " +
            "(#{community.tguid},#{community.CityName},#{community.District},#{community.ResidentialAreaName},#{community.ResidentialAreaAlias},#{community.School},#{community.Description},#{community.NearbySchool},#{community.SupportFacility},#{community.RingRoad},#{community.ManagementCompany},#{community.GreeningRate},#{community.ManagementFees},#{community.ManagementFeesDesp},#{community.BaseFacility},#{community.Network},#{community.PublicSecurity},#{community.CarsAmount},#{community.ParkingRatio},#{community.Parking},#{community.BuildingCategory},#{community.HouseTypes},#{community.HouseType},#{community.EndJobDate},#{community.CompletionDate},#{community.SellDate},#{community.LandUseYearsLimit},#{community.DeveloperCompany},#{community.BuildingStructure},#{community.BuildingArea},#{community.LandArea},#{community.HousingCount},#{community.HouseBuildingCount},#{community.FloorAreaRatio}) " +
            "</foreach> " +
            "</script>")
    boolean insertBatch(List<Community> list);

批量更新

@Update({
            "<script>",
            "<foreach collection='list' item='item' index='index' separator=';'>",
            "update communityinfo b",
            "set b.DistrictName= #{item.DistrictName} where b.id= #{item.id}",
            "</foreach>",
            "</script>"
    })
    boolean batchUpdateName(@Param(value="list")List<Community_copy> list);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值