A possibility is to add an interceptor and map it to your the path of your choice. The interceptor.postHandle
provides access the ModelAndView
after the handler on your controller is executed. Making it possible to add some extra's.
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/my/path"/>
<ref bean="enhancedContentInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
@Component
public class EnhancedContentInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
return true;
}
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
if (request.getContentType().equals("text/html")) {
modelAndView.addObject("tags", tagProvider.getTags());
}
}
public void afterCompletion(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex)
throws Exception {}
}
}