mybatis 中 insert 和insertSelective的区别


insertSelective--有选择性的保存数据

比如User里面有三个字段:id name age password

User u=new user();
u.setName("bill");
mapper.insertSelective(u);

insertSelective执行对应的sql语句的时候,只插入对应的name字段
sql语句如下:
insert into tb_user (name) value ("bill")

insert则是每个字段都要添加一遍

insert into tb_user (id,name,age,password) value(null,"bill",null,null);

项目中根据自己的需求选择对应的方式

猜你喜欢

转载自blog.csdn.net/ldqchat/article/details/82621187