Mybatis中int insertSelective()的相关问题

Posted 玉不琢,不成器;人不学,不知道

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis中int insertSelective()的相关问题相关的知识,希望对你有一定的参考价值。

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);

5、关于insertSelective()返回值,如果插入成功则返回1,失败返回0;对于updateByPrimaryKeySelective()的返回值,成功更新几条返回则返回相应的条数,比如更新了3条,返回值为3,如果更新失败返回0。













以上是关于Mybatis中int insertSelective()的相关问题的主要内容,如果未能解决你的问题,请参考以下文章

Mybatis中int insertSelective()的相关问题

mybatis使用count返回int的方法

mybatis 返回一个类加一个等值int该怎么配置

MyBatis怎么把datetime类型中的年份映射成int

mybatis 配置sql 当返回值为int的时候,resulttype怎么写

(转)mybatis dao的xml文件int类型值为0,条件判断不满足