mybatis插入数据返回当前插入数据的id

获取当前插入数据的id的函数good.getGoodid()

 @RequestMapping(value = "/", method = RequestMethod.POST)
      public @ResponseBody Integer addGood(@RequestBody Good good){

            System.out.println("请求到了");
            System.out.println(good.getName());
            goodService.insertSelective(good);
            System.out.println(good.getGoodid());
            return good.getGoodid();

     }

配置返回当前id的配置useGeneratedKeys=”true” keyProperty=”goodid”

 <insert id="insertSelective" parameterType="com.hanks.entity.Good"  useGeneratedKeys="true" keyProperty="goodid">
insert into good
<trim prefix="(" suffix=")" suffixOverrides="," >
  <if test="goodid != null" >
    goodId,
  </if>
  <if test="locationid != null" >
    locationId,
  </if>
  <if test="name != null" >
    name,
  </if>
  <if test="status != null" >
    Status,
  </if>
  <if test="rfidnumber != null" >
    rfidNumber,
  </if>
  <if test="description != null" >
    description,
  </if>
   <if test="barcode != null" >
    barcode,
  </if>
  <if test="qRCode != null" >
    qRCode,
  </if>

</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
  <if test="goodid != null" >
    #{goodid,jdbcType=INTEGER},
  </if>
  <if test="locationid != null" >
    #{locationid,jdbcType=INTEGER},
  </if>
  <if test="name != null" >
    #{name,jdbcType=VARCHAR},
  </if>
  <if test="status != null" >
    #{status,jdbcType=VARCHAR},
  </if>
  <if test="rfidnumber != null" >
    #{rfidnumber,jdbcType=VARCHAR},
  </if>
  <if test="description != null" >
    #{description,jdbcType=VARCHAR},
  </if>
  <if test="barcode != null" >
    #{barcode,jdbcType=VARCHAR},
  </if>
  <if test="qRCode != null" >
    #{qrcode,jdbcType=VARCHAR},
  </if>
</trim>
 </insert>

//实体类

    package com.hanks.entity;

    public class Good {

    private Integer goodid;


    private Integer locationid;


    private String name;


    private String status;


    private String rfidnumber;


    private String description;


    private String barcode;


    private String qRCode;

    private Location location;

    public Location getLocation() {
        return location;
    }


    public void setLocation(Location location) {
        this.location = location;
    }


    public Integer getGoodid() {
        return goodid;
    }


    public void setGoodid(Integer goodid) {
        this.goodid = goodid;
    }


    public Integer getLocationid() {
        return locationid;
    }


    public void setLocationid(Integer locationid) {
        this.locationid = locationid;
    }


    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }


    public String getStatus() {
        return status;
    }


    public void setStatus(String status) {
        this.status = status == null ? null : status.trim();
    }


    public String getRfidnumber() {
        return rfidnumber;
    }


    public void setRfidnumber(String rfidnumber) {
        this.rfidnumber = rfidnumber == null ? null : rfidnumber.trim();
    }


    public String getDescription() {
        return description;
    }


    public void setDescription(String description) {
        this.description = description == null ? null : description.trim();
    }


    public String getBarcode() {
        return barcode;
    }


    public void setBarcode(String barcode) {
        this.barcode = barcode == null ? null : barcode.trim();
    }

    public String getQrcode() {
        return qRCode;
    }


    public void setQrcode(String qRCode) {
        this.qRCode = qRCode == null ? null : qRCode.trim();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值