How do I could add additional header on Response Body

后端 未结 3 730
离开以前
离开以前 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:38

    Here is the solution as the suggestion of M. Deinum

    @RequestMapping(value="ajaxSuccess", method = RequestMethod.GET)
    public ResponseEntity> ajaxSuccess(){
        Map message = new HashMap();
    
        message.put("severity", "info");
        message.put("location", "/");
        message.put("summary", "Authenticated successfully.");
        message.put("code", 200);
    
        Map json = new HashMap();
        json.put("success", true);
        json.put("message", message);
    
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json; charset=UTF-8");
        headers.add("X-Fsl-Location", "/");
        headers.add("X-Fsl-Response-Code", "302");
        return (new ResponseEntity>(json, headers, HttpStatus.OK));
    }
    

提交回复
热议问题