mybatis insert statement return data Id

mybatis insert statement return data Id

A, mybatis added useGeneratedKeys and keyProperty attributes in the XML Insert statement

1. Set useGeneratedKeys parameter is true, enables the automatic generation of primary keys JDBC support, after the record is added to the primary key may be acquired ID database automatically generated.
2.keyProperty entity class is the primary key field

<insert id="insert" useGeneratedKeys="true" keyProperty="id"> 

Insertion method can be used to accept the object, the returned id field Id subject, obtained using getId id , int used to receive a number of rows inserted affected

Guess you like

Origin blog.csdn.net/LWHuai/article/details/89335913