updateByPrimaryKeySelective会对字段进行判断再更新(如果为Null就忽略更新),如果你只想更新某一字段,可以用这个方法。
updateByPrimaryKey对你注入的字段全部更新
insertSelective和insert的区别?
1、selective的意思是:选择性
2、insertSelective--选择性保存数据;
比如User里面有三个字段:id,name,age,password
但是我只设置了一个字段;
User u=new user();
u.setName("张三");
insertSelective(u);
3、insertSelective执行对应的sql语句的时候,只插入对应的name字段;(主键是自动添加的,默认插入为空)
insert into tb_user (id,name) value (null,"张三");
4、而insert则是不论你设置多少个字段,统一都要添加一遍,不论你设置几个字段,即使是一个。
User u=new user();
u.setName("张三");
insertSelective(u);
insert into tb_user (id,name,age,password) value (null,"张三",null,null);
喜欢就争取,得到就珍惜,错过就忘记,生活其实就这么简单。