Dynamically changing the @ResponseStatus in annotation driven Spring MVC

前端 未结 3 1237
梦如初夏
梦如初夏 2021-02-01 03:01

I am really not sure if this is feasible using Spring 3.2 MVC.

My Controller has a method declared as below:

@RequestMapping(method = RequestMethod.GET)
         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 03:30

    If you return a ResponseEntity directly, you can set the HttpStatus in that:

    // return with no body or headers    
    return new ResponseEntity(HttpStatus.NOT_FOUND);
    

    If you want to return an error other than 404, HttpStatus has lots of other values to choose from.

提交回复
热议问题