Git Product home page Git Product logo

Comments (5)

xwjie avatar xwjie commented on May 25, 2024

ControllerAdvice是有异常的时候才触发,我们的aop除了处理异常还有打印日志等功能。
而且用了ControllerAdvice的话,你成功的时候和失败的时候是否返回格式不一样呢?

from plmcodetemplate.

rabin99 avatar rabin99 commented on May 25, 2024

您好!有2点不是很明白。
1.“ControllerAdvice是有异常的时候才触发”,“而且用了ControllerAdvice的话,你成功的时候和失败的时候是否返回格式不一样呢?”
在项目模版中AOP也是catch (Throwable e)然后处理,而且在ControllerAdvice里面也可以对异常进行instaninstanceof判断类型,也能和模版项目中AOP一样的操作
2.如果post请求,使用ControllerAdvice,还需要获取请求中body中内容,好像取不出来,有什么办法吗?
使用这个aop可以直接用proceedingJoinPoint取。

from plmcodetemplate.

hkbaicfl avatar hkbaicfl commented on May 25, 2024

亲测:ControllerAdvice一样可以处理异常和打印日志。

from plmcodetemplate.

cznno avatar cznno commented on May 25, 2024

@ljhtoljh 可以通过 ServletRequest#getInputStream 来读body, 不过应该有更好的办法吧
另外, ControllerAdvice 里返回的格式也是可以自定义的, 所以格式应该不会有问题. 在实际使用中两种方式似乎感觉不到什么差别, 由ControllerAdvice管理感觉结构更加清晰一点

from plmcodetemplate.

5xiaoxi2 avatar 5xiaoxi2 commented on May 25, 2024

个人理解 xwjie 的AOP可以记录正常日志和异常日志
ControllerAdvice只能记录异常访问日志

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.