From 788e6cbee76ceba6524f3642b15dd8c400811ff8 Mon Sep 17 00:00:00 2001 From: Oleg Marchenko Date: Fri, 18 Jun 2021 08:26:55 +0300 Subject: [PATCH] Add delegation to the bean for the RequestMappingHandlerAdapter.getLastModifiedInternal(..) method if the bean implements the LastModified interface --- .../annotation/RequestMappingHandlerAdapter.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java index 9e5ea44432ec..d056653559a8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java @@ -92,6 +92,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; +import org.springframework.web.servlet.mvc.LastModified; import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; import org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @@ -821,16 +822,21 @@ protected ModelAndView handleInternal(HttpServletRequest request, } /** - * This implementation always returns -1. An {@code @RequestMapping} method can - * calculate the lastModified value, call {@link WebRequest#checkNotModified(long)}, + * This implementation delegates the call to bean, + * if it implements the {@link LastModified} interface or returns -1 by default. + *

An {@code @RequestMapping} method can calculate the lastModified value, + * call {@link WebRequest#checkNotModified(long)}, * and return {@code null} if the result of that call is {@code true}. */ @Override protected long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod) { + Object bean = handlerMethod.getBean(); + if (bean instanceof LastModified) { + return ((LastModified) bean).getLastModified(request); + } return -1; } - /** * Return the {@link SessionAttributesHandler} instance for the given handler type * (never {@code null}).