insert時沒有生成id
????@Test ????public?void?insert(){ ????????User?user?=?new?User(); ????????user.setName("tom"); ????????user.setManagerId(1088248166370832385L); ????????user.setCreateTime(new?Date()); ????????int?insert?=?userMapper.insert(user); ????????System.out.println("insert?=?"?+?insert); ????}
org.springframework.dao.DataIntegrityViolationException:?
### Error updating database.? Cause: java.sql.SQLException: Field 'id' doesn't have a default value
### The error may exist in com/exam/demo/mapper/UserMapper.java (best guess)
### The error may involve com.exam.demo.mapper.UserMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO user? ( name,? ?manager_id, create_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
2021-01-05
同學,你主鍵策略設置的是什么?包括mp和數據庫的,我懷疑你mp設置的為自增,但數據庫沒設置。