mybatis XML代码
<insert id="batchAddDevice" parameterType="List"> <foreach collection="list" item="SceneDevice" index="index" separator=";"> INSERT INTO scene_device(sceneId,deviceId) VALUES(#{SceneDevice.sceneId}, #{SceneDevice.deviceId}) </foreach> </insert>repo中的代码
public void batchAddDevice(@Param("list") List<SceneDevice> list);java service 中的代码
SceneDevice sceneDevice = new SceneDevice();
List<SceneDevice> sceneDevicesList = new ArrayList<>();
sceneDevice.setSceneId(sceneId);
sceneDevice.setDeviceId(deviceId);
sceneDevicesList.add(sceneDevice);
curdRepo.batchAddDevice(sceneDevicesList);