How to set response header in spring mvc

后端 未结 4 1779
猫巷女王i
猫巷女王i 2020-12-13 18:09

I have a method in which i want to set response header cache-control and pragma :-

public String addUser(@Valid User user, BindingResult bindingResult)
{
            


        
4条回答
  •  一整个雨季
    2020-12-13 18:42

    You can manually set headers as follows.

    imports:

    import org.springframework.http.HttpHeaders;
    

    code:

    public ResponseEntity> doSomething() {
       ...
    HttpHeaders respHeaders = new HttpHeaders();
    respHeaders.add("Pragma", "no-cache");
    respHeaders.add("Cache-Control","no-cache,no-store,must-revalidate");
    return new ResponseEntity>(respHeaders, HttpStatus.OK);
    }
    

提交回复
热议问题