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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM