Mybatis配置useGeneratedKeys=“true“ keyProperty=“id“的作用

"message": "\r\n### Error updating database.  Cause: java.sql.SQLException: Field 'id' doesn't have a default value\r\n### The error may exist in file [H:\\runyiwangluo\\gang_spring_cloud\\gang-product-center\\gang-product-starter\\target\\classes\\mapper\\TuyuanProductInfoMapper.xml]\r\n### The error may involve com.gang.product.mapper.TuyuanProductInfoMapper.insertSelective-Inline\r\n### The error occurred while setting parameters\r\n### SQL: insert into tuyuan_product_info      ( product_name )       values ( ? )\r\n### Cause: java.sql.SQLException: Field 'id' doesn't have a default value\n; Field 'id' doesn't have a default value; nested exception is java.sql.SQLException: Field 'id' doesn't have a default value",

说的啥呢 就是说主键自增 ,没有主键信息,

其实就是xml配置的问题

useGeneratedKeys="true" keyProperty="id"的作用

 

useGeneratedKeys 取值范围true、false 默认值是:false。 含义:设置是否使用JDBC的getGenereatedKeys方法获取主键并赋值到keyProperty设置的领域模型属性中

keyProperty 取id的key值

 

你可能感兴趣的:(java工作实战小经验汇总)