我有服务器端方法
@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);
}
我需要在客户端写一个方法,我试过了,但是不起作用
@RequestMapping(value = "/libraryBranches/libraryBranch/updateNumberOfCopies", method = RequestMethod.PUT)
public ResponseEntity<LibraryBranch> updateNumberOfcopies(@RequestParam("numberOfCopies") int numberOfCopies,
@RequestParam("bookId") long bookId, @RequestParam("branchId") long branchId) {
String url = "http://localhost:8091/lms/librarian/libraryBranches/libraryBranch/updateNumberOfCopies";
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url)
// Add query parameter
.queryParam("numberOfCopies", numberOfCopies).queryParam("bookId", bookId)
.queryParam("branchId", branchId);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<LibraryBranch> entity = new HttpEntity<LibraryBranch>(headers);
return restTemplate.exchange(builder.toString(), HttpMethod.PUT, entity, LibraryBranch.class);
}