mybatis批量增加和批量修改

时间:2025-03-18 11:06:10
批量插入的语句
<insert >
		INSERT INTO bus_project_maintenance_detail(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			projectname,
			year,
			username,
			userid,
			coercion_type,
			compulsory_own_funds,
			compulsory_company_borrowing,
			compulsory_mammon_loan,
			isforceorright,
			people_type,
			mainid
		) VALUES
		 	<foreach collection="list" item="busProjectMaintenanceDetail" separator=",">
		 (
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{},
				#{}
		)
			</foreach>
	</insert>


批量修改

<update >
		UPDATE bus_project_maintenance_detail SET
		compulsory_own_funds =
		<foreach collection="list" item="busProjectMaintenanceDetail" index="index"
				 separator=" " open="case id" close="end">
			when #{} then
			#{}
		</foreach>
		,compulsory_company_borrowing =
		<foreach collection="list" item="busProjectMaintenanceDetail" index="index"
				 separator=" " open="case id" close="end">
			when #{} then
			#{}
		</foreach>
		,compulsory_mammon_loan =
		<foreach collection="list" item="busProjectMaintenanceDetail" index="index"
				 separator=" " open="case id" close="end">
			when #{} then
			#{}
		</foreach>
		where id in
		<foreach collection="list" item="busProjectMaintenanceDetail" index="index"
				 separator="," open="(" close=")">
			#{}
		</foreach>
	</update>