Spring for Android是一个框架,旨在提供用于Android应用程序的Spring项目系列的组件。与所有Spring项目一样,Android的真正强大之处在于它的扩展容易程度。
特征
-
适用于Android的Rest Client
-
身份验证支持访问安全API
以下示例说明了如何搜索Google:
// The connection URL
String url = "https://ajax.googleapis.com/ajax/" +
"services/search/web?v=1.0&q={query}";
// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();
// Add the String message converter
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
// Make the HTTP GET request, marshaling the response to a String
String result = restTemplate.getForObject(url, String.class, "Android");
注:传统的用法是HttpCilent方式。