项目需要需要使用MyBatis Generator,generator可生成以下几种的CURD操作。
1.insert()
2.insertSelective()
3.updateByPrimaryKeySelective()
4.updateByPrimaryKey()
5.selectByPrimaryKey()
6.deleteByPrimaryKey()
其中 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);
其他的也是类似的意思。
继续阅读与本文标签相同的文章
上一篇 :
深耕涂色垂直领域,一位开发者的思考和分享
下一篇 :
java设计模式---建造者模式
-
阿里雷卷:Reactive 基金会的成立将对开发方式带来哪些影响?
2026-05-18栏目: 教程
-
8 分钟了解 Kubernetes
2026-05-18栏目: 教程
-
Helm 从入门到实践 | 从 0 开始制作一个 Helm Charts
2026-05-18栏目: 教程
-
阿里云突发性能实例t5 和共享型实例xn4 n4的区别
2026-05-18栏目: 教程
-
【DockerCon2017技术解读】Docker特性介绍
2026-05-18栏目: 教程
