insert与update在加了Selective的区别与不同---通用mapper

…衆ロ難τιáo~ 提交于 2020-01-23 10:04:40

稍微有一段时间不接触通用mapper就把这俩货给忘了以下是—针对通用mapper的解释:

通用mapper中Selective只是做出了对null的检测,如下:

insert 会插入所有字段

insertSelective 只会插入数据不为null的字段

updateByExample根据条件修改所有字段,如果字段为空值接添加数据为null

updateByExampleSelective 根据条件只会修改数据不为null的字段

updateByPrimaryKey 根据主键修改所有字段,如果字段为空值接添加数据为null

updateByPrimaryKeySelective 根据主键只会修改数据不为null的字段


insert好理解,update给个例子吧:

原数据:user:username=1,password=2,sex=null

传入数据为:

username=1,password=null,sex=2

通过updateByPrimaryKey 修改,结果为:

user:username=1,password=null,sex=2

通过updateByPrimaryKeySelective 修改,结果为:

user:username=1,password=2,sex=2

Selective:淘汰

你传进来的数据是空的(null)我就不修改

<if test="name != null">
    name = #{name},
  </if>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!