keyProperty=“id” useGeneratedKeys=“true”
Springboot中 Mybatis 配置文件 Mapper参数
useGeneratedKeys=“true” keyProperty=“id”
useGeneratedKeys设置为 true 时自动会返回
自增的主键id,useGeneratedKeys参数只针对 insert 语句生效
如:
sql语句
CREATE TABLE `test_data1` (
`ID` int(10) NOT NULL AUTO_INCREMENT COMMENT '唯一主键',
`MESSAGE` longtext COMMENT 'JSON报文',
PRIMARY KEY (`ID`)
) mapper
int insertData(TestData testData);
mybaits语句:
insert into test_data1 (ID, MESSAGE)
values (#{id}, #{message})
开始插入之前效果图:
插入后的结果图:
从结果中看出可以数据库自动增长1



