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

后端 未结 4 1179
醉梦人生
醉梦人生 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:33

    Create a NotFoundException class with an @ResponseStatus(HttpStatus.NOT_FOUND) annotation and throw it from your controller.

    @ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "video not found")
    public class VideoNotFoundException extends RuntimeException {
    }
    

提交回复
热议问题