How do you set cache headers in Spring MVC?

后端 未结 10 1052
名媛妹妹
名媛妹妹 2020-12-04 09:23

In an annotation-based Spring MVC controller, what is the preferred way to set cache headers for a specific path?

10条回答
  •  伪装坚强ぢ
    2020-12-04 09:51

    You could use a Handler Interceptor and use the postHandle method provided by it:

    http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/servlet/HandlerInterceptor.html

    postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) 
    

    then just add a header as follows in the method:

    response.setHeader("Cache-Control", "no-cache");
    

提交回复
热议问题