mybatis 新增 返回自定义主键

加粗样式 mybatis mysql 新增返回自定义主键

<selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
selectKey>

完整:

<insert id="save" parameterType="com.jd.m.xz.common.bean.coupon.CouponPoolBean" >

    <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER" >
      SELECT LAST_INSERT_ID()
    selectKey>

    insert into app_xz_coupon_pool
    <trim prefix="(" suffix=")" suffixOverrides=",">
      created, modified,
      <if test="beginTime != null">
        begin_time,
      if>
      <if test="endTime != null">
        end_time,
      if>
      <if test="creator != null">
        creator,
      if>
      <if test="modifier != null">
        modifier,
      if>
      <if test="isDeleted != null">
        is_deleted,
      if>
    trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">

      now(),
      now(),
      <if test="beginTime != null">
        #{beginTime,jdbcType=TIMESTAMP},
      if>
      <if test="endTime != null">
        #{endTime,jdbcType=TIMESTAMP},
      if>
      
      <if test="creator != null">
        #{creator,jdbcType=VARCHAR},
      if>
      <if test="modifier != null">
        #{modifier,jdbcType=VARCHAR},
      if>
      <if test="isDeleted != null">
        #{isDeleted,jdbcType=INTEGER},
      if>
    trim>
  insert>

你可能感兴趣的:(mybatis)