Giter VIP home page Giter VIP logo

Comments (3)

xwjie avatar xwjie commented on May 23, 2024

我不觉得这是一个好主意。
你要保证前后台任何时候看到的是一样的,不要Controll返回的是一个字符串,但有些时候返回到前台的是一个json对象,这是不对的,容易出问题。
如果你的场景用@ResponseBodyAdvice 之后任何时候也是返回同样的数据对象,那就可以。但他能处理异常吗?

from plmcodetemplate.

Nowforpasserby avatar Nowforpasserby commented on May 23, 2024

嗯, 可能我没有阐述清楚
@ResponseBodyAdvice 中会对结果进行包装,包装的对象是我们可选择的:
譬如返回类型为ResultBean不进行再次包装(这样子异常就能处理了,因为异常最终也是返回了一个异常的ResultBean)
类型为 String 的不进行再次包装,还有其他自定义包装类型.
另外前台,我看了下你的技术栈也有 vue
vue 使用 axios 将共同 ResultBean的过滤掉,这样子.
前后台都会无感这个共同的ResultBean,但是事情已经都共同做掉了.
当然这块会让开发傻瓜化,但是对于架构上我觉得是某些方面的好处的,你觉得呢?

from plmcodetemplate.

xwjie avatar xwjie commented on May 23, 2024

后台的错误有几种,一种是系统异常,如链接数据库出错,磁盘io异常,这种可以统一处理过滤掉,业务代码不需要关心,只需要统一提示一下就可以。
另外一种是业务上的错误信息,如参数出错,权限校验失败等,这些业务代码还是要知道的,不是简单统一提示就可以的。所以不能透明。
所以,resultbean的code要分几大类,一类自己关心的,一类自己不关心的。

你投入实际开发中就会发现,不可能过滤掉的,不可能就返回一个字符串或者数字给前台业务代码的。

from plmcodetemplate.

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.