insert时没有生成id

来源:2-1 通用传统模式简介及通用mapper新增方法

慕姐5116453

2021-01-05 10:36

    @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


写回答 关注

1回答

  • 老猿
    2021-01-05 16:25:30

    同学,你主键策略设置的是什么?包括mp和数据库的,我怀疑你mp设置的为自增,但数据库没设置。

MyBatis-Plus入门

MyBatis-Plus框架入门必学课程!

56140 学习 · 381 问题

查看课程

相似问题