实现
insert方法在插入时,会根据实体类的每个属性进行非空判断,只有非空的属性所对应的字段才会出现在SQL语句中。
insertAllColumn方法在插入时,不管属性是否为空,属性所对应的字段都会出现在
SQL语句中。
二者的执行结果是一样的,区别在于,前者会根据实体类的每一个属性值进行一个非空校验,
在插入的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);
}
结果:
数据库中对比效果:
二者的执行结果是一样的
,区别在于,前者会根据实体类的每一个属性值进行一个非空校验,在插入的sql语句中不会出现实体类属性为空的字段;
本文转载自:https://blog.youkuaiyun.com/BADAO_LIUMANG_QIZHI/article/details/89436153