2017-03-26 12 views
0

Im SpringBootアプリケーションには、いくつかのケースを処理するRESTコントローラがあり、これらのケースの1つは別のコントローラに転送する必要があります。Spring ResponseEntity and forward

@PutMapping(
     value = "/rest/endpoint", 
     consumes = MediaType.APPLICATION_JSON_VALUE, 
     produces = MediaType.APPLICATION_JSON_VALUE) 
@ResponseBody 
public ResponseEntity<CustomObject> doPut(@RequestBody myDataToBeHandled) { 

    if(caseAHolds(myDataToBeHandled){ 
     return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); 
    } 
    else if(caseBHolds(myDataToBeHandled){ 
     return new ResponseEntity<>(null, HttpStatus.OK); 
    } 
    else if(caseCHolds(myDataToBeHandled){ 
    // Redirect here 
    } 

} 

私はリダイレクトでこれを行う方法についてはan exampleを見ましたか?別のURLに要求をリダイレクトするために、以下に示すように、以下に示すよう

答えて

0

あなたがLocationヘッダーを設定する必要があります。

@PutMapping(
     value = "/rest/endpoint", 
     consumes = MediaType.APPLICATION_JSON_VALUE, 
     produces = MediaType.APPLICATION_JSON_VALUE) 
@ResponseBody 
public ResponseEntity<CustomObject> doPut(@RequestBody myDataToBeHandled) { 

    if(caseAHolds(myDataToBeHandled){ 
     return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); 
    } 
    else if(caseBHolds(myDataToBeHandled){ 
     return new ResponseEntity<>(null, HttpStatus.OK); 
    } 
    else if(caseCHolds(myDataToBeHandled){ 
    // Redirect here 
    HttpHeaders headers = new HttpHeaders(); 
    headers.add("Location", "ADD_URL_HERE"); 
    return new ResponseEntity<CustomObject>(headers, HttpStatus. OK); 
    } 
} 
関連する問題