报错内容
org.springframework.dao.DataIntegrityViolationException
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.SQLException: Field 'id' doesn't have a default value
### The error may exist in cn/livorth/mapper/UserMapper.java (best guess)
### The error may involve cn.livorth.mapper.UserMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO user ( name, age, email, create_time, update_time ) VALUES ( ?, ?, ?, ?, ? )
### Cause: java.sql.SQLException: Field 'id' doesn't have a default value
; Field 'id' doesn't have a default value; nested exception is java.sql.SQLException: Field 'id' doesn't have a default value
翻译一下就是这样
org.springframework.dao.DataIntegrityViolationException:
###更新数据库时出错。 原因:java.sql.SQLException:字段“ id”没有默认值
###错误可能存在于cn / livorth / mapper / UserMapper.java中(最佳猜测)
###错误可能涉及cn.livorth.mapper.UserMapper.insert-Inline
###设置参数时发生错误
###SQL:INSERT INTO用户(姓名,年龄,电子邮件,create_time,update_time)VALUES(?,?,?,?,?)
###原因:java.sql.SQLException:字段’id’没有默认值; 字段“ id”没有默认值; 嵌套异常为java.sql.SQLException:字段“ id”没有默认值
其中我的User.java
:
public class User {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private Integer age;
private String email;
@TableField(fill = FieldFill.INSERT)
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date updateTime;
}
这个地方我设置的是自增
问题解决(数据库内主键需要设置自增)
然后就成功了