河南河南省住房和城乡建设厅网站,西安外贸建站,驾校网站建设费用,视频生成链接网站int updateByPrimaryKey(User record) thorws SQLException 按主键更新 int updateByPrimaryKeySelective(User record) thorws SQLException 按主键更新值不为null的字段
使用以上的方式更新数据时必须提供主键#xff0c;MyBatis根据主键进行数据记录的更新。 int updateBy…int updateByPrimaryKey(User record) thorws SQLException 按主键更新 int updateByPrimaryKeySelective(User record) thorws SQLException 按主键更新值不为null的字段
使用以上的方式更新数据时必须提供主键MyBatis根据主键进行数据记录的更新。 int updateByExample(User record, UserExample example) thorws SQLException 按条件更新 int updateByExampleSelective(User record, UserExample example) thorws SQLException 按条件更新值不为null的字段
使用以上的方式更新数据时不用提供主键根据Example中构建的条件MyBatis就可以进行数据记录的更新。
例如
update tb_user set name#{name} where mobile#{mobile}
使用MBG实现同等效果就是
public Integer updateUser(String name,String mobile)TbUser user new TbUser();user.setName(name);TbUserExample examplenew TbUserExample();example.createCriteria().andMobileEqualTo(mobile);return userMapper.updateByExampleSelective(user,example);
这样无论TbUser表中有多少字段只会根据mobile字段的情况更新User的name字段。