Java rest模板put方法

Java rest模板put方法,java,resttemplate,Java,Resttemplate,我在服务端有一个使用这种方法的控制器 @PutMapping("/libraryBranches/libraryBranch/updateNumberOfCopies") public ResponseEntity<LibraryBranch> updateNumberOfcopies(@RequestParam("numberOfCopies") int numberOfCopies, @RequestParam("bookId") long bookId, @Re

我在服务端有一个使用这种方法的控制器

@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);
}
@PutMapping(“/librarybranchs/libraryBranch/updateNumberOfCopies”)
公共响应性更新numberOfCopies(@RequestParam(“numberOfCopies”)int numberOfCopies,
@RequestParam(“bookId”)long bookId,@RequestParam(“branchId”)long branchId){
bookCopiesRepository.updateNumberOfCopies(份数、bookId、branchId);
返回新的响应状态(HttpStatus.OK);
}

此资源的客户端方法是什么

我看不出问题出在哪里

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);

这是个骗人的问题吗
PUT localhost///librarybranchs/libraryBranch/updateNumberOfCopies?numberOfCopies=1&bookId=2&branchId=3
。RestTemplate具有put和exchange方法,具体取决于您需要在服务器端资源位于“”上传递的内容(例如标头等),它是带有(@RequestParam(“numberOfCopies”)int numberOfCopies、@RequestParam(“bookId”)long bookId、@RequestParam(“branchId”)long branchId)的put方法。我的问题是如何将所有这些参数从客户端传递到服务器端?这根本不是working@Vladimir,您使用“通过浏览器”的“输入”或“获取”?如果您只是单击浏览器链接,则您正在执行“获取”。使用curl、wget或类似postman的东西进行PUT,并设置请求参数,如我在示例url中所示。您的客户端是Java吗?然后使用RestTemplate。它是浏览器吗?您可以使用jQuery的$.ajax。