稍微有一段时间不接触通用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>
来源:CSDN
作者:Ryan_black
链接:https://blog.csdn.net/Ryan_black/article/details/104073763