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