统一数据返回 其实统一数据返回是运用了AOP(对某一类事情的集中处理)的思维,简单概括就是在我们进行前后端数据交互的时候,能够让后端的数据进行统一的打包封装,返回给前端,便于前后端的数据处理。 其实统一数据返回非常简单,在实现时要加入类注解@ControllerAdvice(这是一个表示控制通知的注解,在接下来的统一异常处理也要运用到),在添加类注解后还要在实现ResponseBodyAdvice接口,然后重写接口的responseAdvice接口和beforeBodyWriter方法即可实现。 添加类注解@ControllerAdvice,实现接口ResponseBodyAdvice 重写responseAdvice方法 重写beforeBodyWriter方法 特殊数据类型特殊处理(String) 2.1 重写responseAdvice方法 responseAdvice方法如下: @Override public boolean supports(MethodParameter returnType, Class converterType) { return true;...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with Server
Contact Server, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack