mybatis+mysql不用存储过程实现多表插入,具体的看代码。
Service:
dwAddDataMapper.saveControllerQrCode(dwAddData); // 保存控制器二维码
vehicleBinding.setControllerId(dwAddData.getId()); // 控制器id
logger.info("saveControllerQrCode:" + dwAddData.getId());
dwAddData.setId(dwAddData.getId());
dwAddDataMapper.saveSyscode(dwAddData); // 保存车辆二维码
vehicleBinding.setQrId(dwAddData.getId()); // 台二维码id
logger.info("saveSyscode:" + dwAddData.getId());
dwAddData.setId(dwAddData.getId());
dwAddDataMapper.saveDwPlateNumber(dwAddData); // 车辆信息表 保存车架号
logger.info("saveDwPlateNumber:" + dwAddData.getId());
mapper:
// 保存控制器二维码
void saveControllerQrCode(DwAddData record);
// 保存车辆二维码
void saveSyscode(DwAddData record);
// 保存车架号
void saveDwPlateNumber(DwAddData record);
mapper.xml
<!-- 控制器二维码 -->
<insert id="saveControllerQrCode" parameterType="com.xe.demo.model.DwAddData" useGeneratedKeys="true" keyProperty="id">
insert IGNORE into base_controller_info (id, controllerQrCode)
values (#{id,jdbcType=BIGINT}, #{dwControllerQrcode,jdbcType=VARCHAR})
</insert>
<!-- 车辆二维码 -->
<insert id="saveSyscode" parameterType="com.xe.demo.model.DwAddData" useGeneratedKeys="true" keyProperty="id">
insert IGNORE into base_system_qrcode (id, controllerQrCode, batchId)
values (#{id,jdbcType=BIGINT}, #{syscode,jdbcType=VARCHAR}, "0")
</insert>
<!-- 车辆信息表 车架号 -->
<insert id="saveDwPlateNumber" parameterType="com.xe.demo.model.DwAddData" useGeneratedKeys="true" keyProperty="id">
insert IGNORE into veh_vehicle_information (id, frame_number)
values (#{id,jdbcType=BIGINT}, #{dwPlateNumber,jdbcType=VARCHAR})
</insert>