0
点赞
收藏
分享

微信扫一扫

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


实现

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方法的区别_SQL

测试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方法的区别_Test_02

数据库中对比效果:

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

举报

相关推荐

0 条评论