com.emily.infrastructure.web.response.handler.ResponseAdviceHandler Maven / Gradle / Ivy
The newest version!
package com.emily.infrastructure.web.response.handler;
import com.emily.infrastructure.common.RegexPathMatcher;
import com.emily.infrastructure.json.JsonUtils;
import com.emily.infrastructure.web.exception.type.AppStatusType;
import com.emily.infrastructure.web.response.ResponseProperties;
import com.emily.infrastructure.web.response.annotation.ApiResponsePackIgnore;
import com.emily.infrastructure.web.response.entity.BaseResponse;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import javax.annotation.Nonnull;
/**
* ---------------------------------------------------------------
* 使用说明:
* 1.此AOP拦截器只会拦截到使用@ResponseBody获取ResponseEntity返回的响应;
* 2.如果在springboot中使用HttpServletResponse.getOutputStream.write()将图片返回给客户端,那么ResponseBodyAdvice是无法拦截到响应;
* RequestMapping参数说明:
* 1.produces:指定返回的内容类型,仅当请求header中的Accept类型中包含该指定类型才能返回;
* 2.consumes:指定处理请求的提交内容类型(ContentType),如:application/json
* ---------------------------------------------------------------
*
* 返回值包装类统一处理
*
* @author Emily
* @since Created in 2023/7/1 3:02 PM
*/
@RestControllerAdvice
public class ResponseAdviceHandler implements ResponseBodyAdvice