首页 > 其他 > 详细

Mybatis中insert和insertSelective区别

时间:2020-08-26 13:58:49      阅读:144      评论:0      收藏:0      [点我收藏+]

两者的区别在于如果选择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’);

Mybatis中insert和insertSelective区别

原文:https://www.cnblogs.com/king0207/p/13564516.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!