Return HTTP 204 on null with spring @RestController

前端 未结 7 2017
旧时难觅i
旧时难觅i 2020-12-25 12:10

This returns 200 OK with Content-Length: 0

@RestController
public class RepoController {
    @RequestMapping(value = \"/document/{id}\", method = RequestMeth         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-25 12:56

    You can try this :

    @RestController
    public class RepoController {
    
        @RequestMapping(value = "/document/{id}", method = RequestMethod.GET)
        public ResponseEntity getDocument(@PathVariable long id) {
    
           if(noError) {
               ............
               return new ResponseEntity(HttpStatus.OK); 
           }
           else {
               return new ResponseEntity(HttpStatus.BAD_REQUEST);
           }
       }
    }
    

    Uou need to change HttpStatus.BAD_REQUEST with the equivalent for 204 code status

提交回复
热议问题