How to throw an exception back in JSON in Spring Boot

前端 未结 6 1197
-上瘾入骨i
-上瘾入骨i 2020-12-29 09:11

I have a Request Mapping -

  @RequestMapping(\"/fetchErrorMessages\")
  public @ResponseBody int fetchErrorMessages(@RequestParam(\"startTime\") String star         


        
6条回答
  •  醉梦人生
    2020-12-29 09:40

    you can create NotFoundException class with @ResponseStatus annotation like below:

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public class NotFoundException extends RuntimeException {
       public NotFoundException() {
       }
    
       public NotFoundException(String message) {
        super(message);
       }
    
    }
    

提交回复
热议问题