• Mysql插入数据返回对应的自增id(mybatis)


    输入的参数应该是一个model,有id属性,当插入完成后,新产生的表中的自增id会赋值为输入的参数对象中的id

    <insert id="addFinanceApply" parameterType="com.....model.FinanceApply">
            <selectKey resultType="int" keyProperty="id" order="AFTER">
                SELECT last_insert_id()
            </selectKey>
            INSERT
            INTO finance_apply
            (money,
            from_account_id,
            to_account_id,
            apply_type,
            applier_id,
            apply_time,
            approver_id,
            <if test="approvedTime!= null">
                approved_time,
            </if>
            status,
            remark,
            business_id,
            bank_order_id,
            qcompany_id,
            qaccount_id,
            payer,
            approval_remark,
            recharge_date,
            is_company,
            applier_name,
            approver_name,
            customer_name,
            customer_account,
            customer_account_number,
            customer_city,
            <if test="resetStatus != null">
                reset_status,
            </if>
            <if test="manualClaimStatus != null">
                manual_claim_status,
            </if>
            <if test="financialSystemType != null and financialSystemType != '' ">
                financialSystem_Type,
            </if>
            transfer_type,
            transaction_id
            )VALUES(
            #{money},
            #{fromAccountId},
            #{toAccountId},
            #{applyType},
            #{applierId},
            now(),
            #{approverId},
            <if test="approvedTime != null">
                #{approvedTime},
            </if>
            #{status},
            #{remark},
            #{businessId},
            #{bankOrderId},
            #{qcompanyId},
            #{qaccountId},
            #{payer},
            #{approvalRemark},
            #{rechargeDate},
            #{isCompany},
            #{applierName},
            #{approverName},
            #{customerName},
            #{customerAccount},
            #{customerAccountNumber},
            #{customerCity},
            <if test="resetStatus != null">
                #{resetStatus},
            </if>
            <if test="manualClaimStatus != null">
                #{manualClaimStatus},
            </if>
            <if test="financialSystemType != null and financialSystemType != '' ">
                #{financialSystemType},
            </if>
            #{transferType},
            #{transactionId}
            );
        </insert>
  • 相关阅读:
    java内部类
    接口与继承
    数据结构
    数据I/O流
    课程总结
    第六次实训作业异常处理
    常用类的课后作业
    窗口实训1
    实训作业4
    实训作业3
  • 原文地址:https://www.cnblogs.com/lingear/p/3042658.html
Copyright © 2020-2023  润新知