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;


说明:

返回的主键值会直接赋值到实体,而不是方法体的返回值。