MybatisPlus中insert方法与insertAllColumn方法的区别

场景

项目搭建专栏:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194

实现

insert方法在插入时,会根据实体类的每个属性进行非空判断,只有非空的属性所对应的字段才会出现在SQL语句中。

insertAllColumn方法在插入时,不管属性是否为空,属性所对应的字段都会出现在

SQL语句中。

测试insert插入语句:

/***
  * 测试insert
  */
 @Test
 public void testInsert() {
  Employee employee = new Employee();
  employee.setName("insert测试");
  employee.setAge(23);
  int result = employeeMapper.insert(employee);
  System.out.println("************************"+result);
  Integer id = employee.getId();
  System.out.println("*********************"+id);
 }

 

结果:

MybatisPlus中insert方法与insertAllColumn方法的区别_第1张图片

测试insertAllColumn插入:

/***
  * 测试insertAllColumn
  */
 @Test
 public void testInsertAllColumn() {
  Employee employee = new Employee();
  employee.setName("insertAllColumn测试");
  employee.setAge(23);
  int result = employeeMapper.insertAllColumn(employee);
  System.out.println("************************"+result);
  Integer id = employee.getId();
  System.out.println("*********************"+id);
 }

结果:

MybatisPlus中insert方法与insertAllColumn方法的区别_第2张图片

数据库中对比效果:

MybatisPlus中insert方法与insertAllColumn方法的区别_第3张图片

你可能感兴趣的:(MyBatisPlus)