获取当前插入数据的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();
}
}