MyBatis 3在Insert之后返回主键
XML:
<insert id="addUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
注解:
@Insert("your sql goes here")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int insert(FileAttachment fileAttachment) throws Exception;
说明:
返回的主键值会直接赋值到实体,而不是方法体的返回值。
参考:
https://stackoverflow.com/questions/12103606/get-the-id-of-last-inserted-record-in-mybatis

浙公网安备 33010602011771号