彩票网站注册营销策划与运营方案
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 example=new TbUserExample();example.createCriteria().andMobileEqualTo(mobile);return userMapper.updateByExampleSelective(user,example);
这样无论TbUser表中有多少字段,只会根据mobile字段的情况更新User的name字段。