在abator中可生成iBatis的代码。其中,Sql_map中带有的两个函数是:
-
updateByPrimaryKeySelective
只是更新新的model中不为空的字段 -
updateByPrimaryKey
将为空的字段在数据库中置为NULL
例如
![img_58e8435c95e3f3bbeeeca9adf57552a0.png](https://i-blog.csdnimg.cn/blog_migrate/11c3acb16258d865ac4d16df2406aa69.png)
CartServiceImpl#update
若DAO中使用的是
updateByPrimaryKeySelective
,则按照不为空的值去更新。
如果使用
updateByPrimaryKey
,这在未定义的字段更新后就没有了。
SQL语句对比分析
![img_444f37e052be2cae03365fe8e0b87bf0.png](https://i-blog.csdnimg.cn/blog_migrate/10d8be0f4b892d042e1330f0116ba3b7.png)
一系列的isNull判断
![img_0ecc1f97d74a5f51a83542e40475d026.png](https://i-blog.csdnimg.cn/blog_migrate/46b6618a5baffeb3b46ed42a25c7d581.png)
没有判断,直接加载