How do I could add additional header on Response Body

后端 未结 3 726
离开以前
离开以前 2021-02-02 11:08

Just see the code snippet of SpringMVC-3.2.x controller action method. Its quite easy to generate JSON but unable to add addtional custom header only f

3条回答
  •  死守一世寂寞
    2021-02-02 11:40

    You can also use HttpServletResponse for adding your status and headers in a more easy way:

    @RequestMapping(value="ajaxSuccess", method = RequestMethod.GET)
    @ResponseBody
    public String ajaxSuccess(HttpServletResponse response) {
      response.addHeader("header-name", "value");
      response.setStatus(200);
      return "Body";
    }
    

    Therefore you need to add following maven dependency as provided:

    
        org.apache.tomcat
        tomcat-servlet-api
        7.0.53
        provided
    
    

提交回复
热议问题