Mybatis insert语句书写insert
id=
"insertSelective"
useGeneratedKeys=
"true"
keyProperty=
"fileId"
parameterType=
"fileAlias" > insert into t_file_info ...
</insert>
useGeneratedKeys:是否生成主键
重点是写上 keyProperty = "fileId" fileId对应 fileAlias实体类的属性值
public class TFileInfo extends BaseModel implements Serializable {
private Integer fileId;
private String fileName;
//保存入库
fileInfoDao.insertSelective(fileInfo);
//返回入库ID
id = fileInfo.getFileId();//该语句是重点,必须自己手动获取到自增的id主键
上述sql执行完毕后,fileInfo对象里的fileID就会被自动附加上fileId