在abator中可生成iBatis的代码。其中,Sql_map中带有的两个函数是:

1 源码对比
  • updateByPrimaryKeySelective
    只是更新新的model中不为空的字段
    mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解_MyBtis
  • updateByPrimaryKey
    将为空的字段在数据库中置为NULL
    mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解_MyBtis_02
2 实战案例

mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解_MyBtis_03
若DAO中使用的是 updateByPrimaryKeySelective,则按照不为空的值去更新。
如果使用updateByPrimaryKey,这在未定义的字段更新后就没有了。

3 项目实战中的Mapper SQL语句对比

mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解_Java_04
一系列的isNull判断
mybatis 中的 updateByPrimaryKey 与 updateByPrimaryKeySelective 的原理与区别实战详解_MyBtis_05

没有判断,直接加载