Coder Social home page Coder Social logo

Comments (9)

lihengming avatar lihengming commented on May 16, 2024

我觉得没必要吧,只要没有出现异常,肯定是成功的,你怎么看?

from spring-boot-api-project-seed.

lihengming avatar lihengming commented on May 16, 2024
   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确实是会返回影响的行数,我把它省略了,因为在使用中从来没用到过。

from spring-boot-api-project-seed.

0000005 avatar 0000005 commented on May 16, 2024

你这么说好像也有点道理,这就意味着。如果影响的行数为0,那么必定会抛异常?

from spring-boot-api-project-seed.

lj-example avatar lj-example commented on May 16, 2024

from spring-boot-api-project-seed.

0000005 avatar 0000005 commented on May 16, 2024

是的,那这个影响行数对调用者来说就有意义了。
调用者可以知道按照某个条件是否 执行成功了。

from spring-boot-api-project-seed.

lihengming avatar lihengming commented on May 16, 2024

加上是很容易的,关键在于有多少人会去处理这个返回值?每次调用 Service 的CRUD方法都会去判断一下影响的记录数?

from spring-boot-api-project-seed.

michael-ancestor avatar michael-ancestor commented on May 16, 2024

这个在实际业务中,场景确实有的

from spring-boot-api-project-seed.

xiongzhao1217 avatar xiongzhao1217 commented on May 16, 2024

返回影响行数还是很有必要的,可以避免代码中锁的使用,如更新订单状态(update ... set status = 'success' where status = 'wait_paying'),更新成功(影响行数=1)执行后续的操作,否则表示订单已经被更新过,直接return

from spring-boot-api-project-seed.

Huptzzz avatar Huptzzz commented on May 16, 2024

更新一个条件不存在的时候就是0吧,感觉是需要拿返回值来作为下一步业务处理的依据

from spring-boot-api-project-seed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.