25 Nisan 2022 Pazartesi

SpringMVC RequestBodyAdviceAdapter Sınıfı

Giriş
Spring ile hazır gelen advice'lardan bir tanesi

Örnek
Şöyle yaparız
import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceAdapter;

@ControllerAdvice
public class RequestBodyInterceptor extends RequestBodyAdviceAdapter {

  @Autowired
  HttpServletRequest request;

  @Override
  public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
    ...
    return super.afterBodyRead(body, inputMessage, parameter, targetType, converterType);
  }

  @Override
  public boolean supports(MethodParameter methodParameter, Type targetType, 
    Class<? extends HttpMessageConverter<?>> converterType) {
        return true;
  }
}

Hiç yorum yok:

Yorum Gönder