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);
 }

结果:

测试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);
 }

结果:

数据库中对比效果:

猜你喜欢

转载自blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89436153
今日推荐