Mybatis中的insert和insertSelective的区别

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

体现在sql上为:

student表:

id,name,age

实体代码为:

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

使用insert时执行的sql语句为:

insert into student(id,name,age) values1,‘zhangsan’,null);

而使用insertSelective时执行的sql语句为:

insert into student(id,name) values1,‘zhangsan’);

转载于:https://blog.csdn.net/syilt/article/details/90750850