Spring: Returning empty HTTP Responses with ResponseEntity doesn't work

前端 未结 6 1047
梦如初夏
梦如初夏 2020-12-05 09:47

We are implementing a REST API with Spring (4.1.1.). For certain HTTP requests, we would like to return a head with no body as a response. However, using ResponseEntit

6条回答
  •  心在旅途
    2020-12-05 10:10

    You can also not specify the type parameter which seems a bit cleaner and what Spring intended when looking at the docs:

    @RequestMapping(method = RequestMethod.HEAD, value = Constants.KEY )
    public ResponseEntity taxonomyPackageExists( @PathVariable final String key ){
        // ...
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
    

提交回复
热议问题