How to return 404 response status in Spring Boot @ResponseBody - method return type is Response?

后端 未结 4 1148
醉梦人生
醉梦人生 2021-01-30 20:24

I\'m using Spring Boot with @ResponseBody based approach like the following:

@RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET)
public @Respons         


        
4条回答
  •  天涯浪人
    2021-01-30 20:38

    Your original method can return ResponseEntity (doesn't change your method behavior):

    @RequestMapping(value = VIDEO_DATA_PATH, method = RequestMethod.GET)
    public ResponseEntity getData(@PathVariable(ID_PARAMETER) long id, HttpServletResponse res{
    ... 
    }
    

    and return the following:

    return new ResponseEntity(HttpStatus.NOT_FOUND);
    

提交回复
热议问题