MySQL insert sql 返回自增id

xml
<insert id="addMain"  useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.hopedove.coreserver.vo.vpm.ForeignTradeOutboundOrderVO">
        insert into aps_foreign_trade_ex_warehouse
        (invoiceNumber,factoryId,mainStyleNumber,customerId,customerIdentifyName,quantity,passQty,status,shipmentNumber,
         disabled,createUserId,createUserName,createDatetime,createDeptId,createIp,updateUserId,
         updateUserName,updateDatetime,updateDeptId,updateIp)
        values(#{invoiceNumber},#{factoryId},#{mainStyleNumber},#{customerId},#{customerIdentifyName},#{quantity},#{passQty},#{status},#{shipmentNumber},
           #{disabled},#{createUserId},#{createUserName},#{createDatetime},#{createDeptId},#{createIp},
           #{updateUserId},#{updateUserName},#{updateDatetime},#{updateDeptId},#{updateIp})
    </insert>

  dao

  int addMain(ForeignTradeOutboundOrderVO vo);

  实现类

        vo.setInvoiceNumber(code);
            vo.setFactoryId(factoryId);
            vo.setDisabled(0);
            vo.setStatus(0);
            VOUtil.fillCreate(vo);
            iForeignTradeOutboundOrderDao.addMain(vo);
            List<ForeignTradeOutboundOrderDetailVO> details = vo.getDetails();
            details.forEach(item->{
                item.setFactoryId(factoryId);
                item.setParentId(vo.getId());
                VOUtil.fillCreate(item);
            });

  

vo.getId()就可以直接获取到了

posted @ 2024-09-04 18:03  Li_ll  Views(21)  Comments(0Edit  收藏  举报