mybatis insert operation returns the primary key
Mybatis insert statement writing
<insert id="insertSelective" useGeneratedKeys="true" keyProperty="fileId" parameterType="fileAlias" >
insert into t_file_info ...
</insert>
useGeneratedKeys: whether to generate a primary key The
key is to write keyProperty = "fileId " fileId corresponds to the attribute value of the fileAlias entity class
public class TFileInfo extends BaseModel implements Serializable {
private Integer fileId;
private String fileName;
//Save the
fileInfoDao.insertSelective(fileInfo);
//Return the ID
id = fileInfo.getFileId() ;
After the above sql is executed, the fileID in the fileInfo object will be automatically appended with the fileId and
transferred from http://my.oschina.net/francis0115/blog/193543
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326771947&siteId=291194637
Ranking