Mybatis中insert和insertSelective区别

两者的区别在于如果选择insert 那么所有的字段都会添加一遍即使没有值,而insertSelective则会判断非空才进行插入。

体现在sql上为:

student表:

id,name,age

实体代码为:

  1.  
    Student student = new Student();
  2.  
    student.setId(1);
  3.  
    student.setName("张三");

使用insert时执行的sql语句为:insert into student(id,name,age) values (1,‘zhangsan’,null);

 

而使用insertSelective时执行的sql语句为:insert into student(id,name) values (1,‘zhangsan’);

posted @ 2020-08-26 13:12  路要一步一步走  阅读(1884)  评论(0编辑  收藏  举报