package cc.mrbird.febs.common.advise; import cc.mrbird.febs.common.contants.AppContants; import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice; import java.io.IOException; import java.lang.reflect.Type; import java.util.List; /** * @author wzy * @date 2022-06-14 **/ @ControllerAdvice public class MyRequestBodyAdvise implements RequestBodyAdvice { @Override public boolean supports(MethodParameter methodParameter, Type type, Class> aClass) { return true; } @Override public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter methodParameter, Type type, Class> aClass) throws IOException { if(!AppContants.ENCRYPT_METHOD.contains(methodParameter.getMethod().getName())) { return inputMessage; } return new MyHttpInputMessage(inputMessage.getBody()); } @Override public Object afterBodyRead(Object body, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class> aClass) { return body; } @Override public Object handleEmptyBody(Object o, HttpInputMessage httpInputMessage, MethodParameter methodParameter, Type type, Class> aClass) { return o; } }