我在服务端有使用此方法的控制器
@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);
}
此资源在客户端将采用什么方法?
答案 0 :(得分:0)
我看不出问题出在哪里。
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);