Comments (5)
ControllerAdvice是有异常的时候才触发,我们的aop除了处理异常还有打印日志等功能。
而且用了ControllerAdvice的话,你成功的时候和失败的时候是否返回格式不一样呢?
from plmcodetemplate.
您好!有2点不是很明白。
1.“ControllerAdvice是有异常的时候才触发”,“而且用了ControllerAdvice的话,你成功的时候和失败的时候是否返回格式不一样呢?”
在项目模版中AOP也是catch (Throwable e)然后处理,而且在ControllerAdvice里面也可以对异常进行instaninstanceof判断类型,也能和模版项目中AOP一样的操作
2.如果post请求,使用ControllerAdvice,还需要获取请求中body中内容,好像取不出来,有什么办法吗?
使用这个aop可以直接用proceedingJoinPoint取。
from plmcodetemplate.
亲测:ControllerAdvice一样可以处理异常和打印日志。
from plmcodetemplate.
@ljhtoljh 可以通过 ServletRequest#getInputStream 来读body, 不过应该有更好的办法吧
另外, ControllerAdvice 里返回的格式也是可以自定义的, 所以格式应该不会有问题. 在实际使用中两种方式似乎感觉不到什么差别, 由ControllerAdvice管理感觉结构更加清晰一点
from plmcodetemplate.
个人理解 xwjie 的AOP可以记录正常日志和异常日志
ControllerAdvice只能记录异常访问日志
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的疑问
- 大佬能否把常用工具类提供一下
- 如何看待 ResponseBodyAdvice HOT 3
- 单元测试 HOT 6
- 更新 xstream dependency version
- 导入代码报错 HOT 1
- 请问是完整的工程吗? HOT 2
- 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.