spring-boot-api-project-seed
spring-boot-api-project-seed copied to clipboard
生成的代码增删改查建议 返回影响的行数
我觉得没必要吧,只要没有出现异常,肯定是成功的,你怎么看?
public void save(T model) {
mapper.insertSelective(model);
}
public void save(List<T> models) {
mapper.insertList(models);
}
public void deleteById(Integer id) {
mapper.deleteByPrimaryKey(id);
}
public void deleteByIds(String ids) {
mapper.deleteByIds(ids);
}
public void update(T model) {
mapper.updateByPrimaryKeySelective(model);
}
你说的是这些吧?Mapper确实是会返回影响的行数,我把它省略了,因为在使用中从来没用到过。
你这么说好像也有点道理,这就意味着。如果影响的行数为0,那么必定会抛异常?
如果没有异常是正确的,影响行数为0不一定出异常吧。比如按照条件修改的sql.
------------------ 原始邮件 ------------------ 发件人: "JerryYin";[email protected]; 发送时间: 2017年9月5日(星期二) 上午10:12 收件人: "lihengming/spring-boot-api-project-seed"[email protected]; 抄送: "Subscribed"[email protected]; 主题: Re: [lihengming/spring-boot-api-project-seed] 生成的代码增删改查建议 返回影响的行数 (#49)
你这么说好像也有点道理,这就意味着。如果影响的行数为0,那么必定会抛异常?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
是的,那这个影响行数对调用者来说就有意义了。 调用者可以知道按照某个条件是否 执行成功了。
加上是很容易的,关键在于有多少人会去处理这个返回值?每次调用 Service
的CRUD方法都会去判断一下影响的记录数?
这个在实际业务中,场景确实有的
返回影响行数还是很有必要的,可以避免代码中锁的使用,如更新订单状态(update ... set status = 'success' where status = 'wait_paying'),更新成功(影响行数=1)执行后续的操作,否则表示订单已经被更新过,直接return
更新一个条件不存在的时候就是0吧,感觉是需要拿返回值来作为下一步业务处理的依据