2013-01-04 45 views
1

我正在使用Spring-Android使用API​​,但是當我嘗試做PATCH時,我注意到RestTemplate中沒有相應的方法。 文檔建議我使用交換或執行,但我很難理解如何。 PATCH似乎並未包含在Spring-Android 1.0.1 HttpMethod中。Http PATCH with Spring Android

關於如何進行的任何想法?

回答

1

有時代碼更好地解釋它:

如果你有了解RestTemplage.postForEntity(String url, Object request, Class<T> responseType, Object... uriVariables)確實的方法,然後看看它是如何實現的方式。

public <T> ResponseEntity<T> postForEntity(String url, Object request, 
        Class<T> responseType, Object... uriVariables) 
        throws RestClientException { 

    HttpEntityRequestCallback requestCallback = 
            new HttpEntityRequestCallback(request, responseType); 
    ResponseEntityResponseExtractor<T> responseExtractor = 
            new ResponseEntityResponseExtractor<T>(responseType); 
    return execute(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables); 
} 

我希望你能理解你如何將這個例子映射到其他Http方法。

如果您還沒有春天的代碼添加到您的IDE,你可以看看這個url for the RestTemplate code

+0

謝謝,我想我現在好理解,但execute方法接受一個HttpPost作爲參數,並SpringAndroid似乎缺乏PATCH。儘管我可以看到它被添加到github上的spring源代碼中。 – Qw4z1

+0

@ Qw4z1你的意思是HttpMethod.POST?還有一個HttpMethod.PATCH! – Ralph

+0

http://static.springsource.org/spring-android/docs/1.0.x/api/如果您查看Spring Android的javadoc,您將看到版本1.0.x沒有PATCH,因爲我是使用1.0.1我在我的HttpMethod中沒有PATCH。 – Qw4z1