1、返回插入的行
mapper中使用 useGeneratedKeys="true" keyProperty="entity.id"
1 <insert id="insert" parameterType="com.hx78.ruler.data.dao.entity.MeasureRecord" useGeneratedKeys="true" keyProperty="measureRecord.id"> 2 INSERT INTO 3 db_ruler.t_measure_record( 4 <include refid="Based_Column_List_Without_ID"/> 5 ) 6 VALUES ( 7 #{measureRecord.createTime} 8 ) 9 </insert>
service中要使用插入的entity返回,这里只返回插入的行的ID
1 @Override 2 public Long add(MeasureRecord measureRecord) { 3 measureRecordMapper.insert(measureRecord); 4 return measureRecord.getId(); 5 }