RestTemplate пут метод - PullRequest
       7

RestTemplate пут метод

0 голосов
/ 22 февраля 2019

У меня есть контроллер с этим методом на стороне службы

@PutMapping("/libraryBranches/libraryBranch/updateNumberOfCopies")
public ResponseEntity<LibraryBranch> updateNumberOfcopies(@RequestParam("numberOfCopies") int numberOfCopies,
        @RequestParam("bookId") long bookId, @RequestParam("branchId") long branchId) {
    bookCopiesRepository.updateNumberOfCopies(numberOfCopies, bookId, branchId);
    return new ResponseEntity<LibraryBranch>(HttpStatus.OK);
}

Каким будет метод на стороне клиента для этого ресурса?

1 Ответ

0 голосов
/ 22 февраля 2019

Я не вижу, в чем проблема ..

String url = "http://localhost:8080/libraryBranches/libraryBranch/updateNumberOfCopies";
RestTemplate restTemplate = new RestTemplate();

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.AUTHORIZATION, "urAccessToken");

UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
        .queryParam("numberOfCopies", "")
        .queryParam("bookId", "")
        .queryParam("branchId", "");

HttpEntity httpEntity = new HttpEntity(httpHeaders);

restTemplate.exchange(builder.toUriString(), HttpMethod.PUT, httpEntity, LibraryBranch.class);
...