Comments (3)
我不觉得这是一个好主意。
你要保证前后台任何时候看到的是一样的,不要Controll返回的是一个字符串,但有些时候返回到前台的是一个json对象,这是不对的,容易出问题。
如果你的场景用@ResponseBodyAdvice 之后任何时候也是返回同样的数据对象,那就可以。但他能处理异常吗?
from plmcodetemplate.
嗯, 可能我没有阐述清楚
@ResponseBodyAdvice 中会对结果进行包装,包装的对象是我们可选择的:
譬如返回类型为ResultBean不进行再次包装(这样子异常就能处理了,因为异常最终也是返回了一个异常的ResultBean)
类型为 String 的不进行再次包装,还有其他自定义包装类型.
另外前台,我看了下你的技术栈也有 vue
vue 使用 axios 将共同 ResultBean的过滤掉,这样子.
前后台都会无感这个共同的ResultBean,但是事情已经都共同做掉了.
当然这块会让开发傻瓜化,但是对于架构上我觉得是某些方面的好处的,你觉得呢?
from plmcodetemplate.
后台的错误有几种,一种是系统异常,如链接数据库出错,磁盘io异常,这种可以统一处理过滤掉,业务代码不需要关心,只需要统一提示一下就可以。
另外一种是业务上的错误信息,如参数出错,权限校验失败等,这些业务代码还是要知道的,不是简单统一提示就可以的。所以不能透明。
所以,resultbean的code要分几大类,一类自己关心的,一类自己不关心的。
你投入实际开发中就会发现,不可能过滤掉的,不可能就返回一个字符串或者数字给前台业务代码的。
from plmcodetemplate.
Related Issues (20)
- ResultPage呢 HOT 3
- 关于spring aop 切面引入的问题
- 怎么找不到plm.common.utils包啊?
- 如何自定义错误返回码呢 HOT 1
- jdk版本的问题 HOT 2
- 自定义异常问题
- 帅哥,写的真不错,能提供pdf版本吗, HOT 1
- 使用maven tomcat7插件无法启动项目 HOT 2
- 异常处理疑问
- 请问返回ResultBean的话,视图如何指定 HOT 3
- aop的疑问
- 大佬能否把常用工具类提供一下
- 单元测试 HOT 6
- 更新 xstream dependency version
- 导入代码报错 HOT 1
- 请问是完整的工程吗? HOT 2
- 请问不要使用ControllerAdvice代替AOP的原因是什么? HOT 5
- log4j mdc找不到 HOT 1
- configs.getAll()方法带参数返回加total是不是就要返回Map类型? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plmcodetemplate.