コード例 #1
0
  @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
  @ResponseStatus(HttpStatus.CREATED)
  public ResponseEntity<BasePlayer> savePlayer(
      @RequestBody BasePlayer player, UriComponentsBuilder ucb) {
    BasePlayer saved = playerRepository.save(player);

    HttpHeaders headers = new HttpHeaders();
    URI locationUri = ucb.path("/player/").path(saved.getLastName()).build().toUri();
    headers.setLocation(locationUri);

    ResponseEntity<BasePlayer> responseEntity =
        new ResponseEntity<BasePlayer>(saved, headers, HttpStatus.CREATED);
    return responseEntity;
  }
コード例 #2
0
 @RequestMapping(value = "/{lastName}", method = RequestMethod.GET, produces = "application/json")
 public BasePlayer playerByLastName(@PathVariable String lastName) {
   return playerRepository.findByLastName(lastName);
 }