RestTemplate PATCH request

后端 未结 5 1210
旧巷少年郎
旧巷少年郎 2020-12-13 17:48

I have the following definition for PersonDTO:

public class PersonDTO
{
    private String id
    private String firstName;
    private String lastName;
             


        
5条回答
  •  悲&欢浪女
    2020-12-13 18:32

    I have added the below code in the java file. It worked for me.

    String url="Your API URL";
    RestTemplate restTemplate = new RestTemplate();
    HttpClient httpClient = HttpClientBuilder.create().build();
    restTemplate.setRequestFactory(new 
    HttpComponentsClientHttpRequestFactory(httpClient));    
    HttpHeaders reqHeaders = new HttpHeaders();
    reqHeaders.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity requestEntity = new HttpEntity(requestJson, reqHeaders);
    ResponseEntity responseEntity=restTemplate.exchange(url, HttpMethod.PATCH, 
    requestEntity, String.class);
    

    Also, need to add the below dependency in the pom.xml file.

    
        org.apache.httpcomponents
        httpclient
    
    

提交回复
热议问题