私の春データRESTアプリでは、私は、次のコントローラがあります。Spring Data RESTコントローラで要求パラメータを適切に処理する方法は?
@RestController
@RequestMapping("/people")
public class PersonController {
@RequestMapping(value = "/**", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> savePerson(@RequestBody Person person, UriComponentsBuilder b, @RequestParam Map<String, ?> id) {
UriComponents uriComponents =
b.path("/people/{id}").buildAndExpand(id);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(uriComponents.toUri());
responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity<String>("Hello World\n\n", responseHeaders, HttpStatus.CREATED);
}
}
私は次のポストます
curl -i -X POST -H "Content-Type:application/json" -d '{ "firstName" : "Frodo", "lastName" : "Baggins" }' http://localhost:8080/people
を、私はこのエラーを取得する:
{"timestamp":1476418616900,"status":500,"error":"Internal Server Error","exception":"java.lang.IllegalArgumentException","message":"Map has no value for 'id'","path":"/people"}
は何べき私はこのエラーを修正するために変更しますか?あなたがid
に合格していない
あなたは正しいです。ありがとう! –