Original article: http://blog.csdn.net/hongchangfirst/article/details/7934990
Author: hongchangfirst
Spring has an android client interface, which can easily call web service. First, we need to import these dependency packages. Where:
Maven dependencies are as follows:
<Dependency>
<Groupid> org. springframework. Android </groupid>
<Artifactid> spring-Android-rest-template </artifactid>
<Version> 1.0.0.release </version>
</Dependency>
The following two packages are obtained:
Spring-android-core-1.0.0.RELEASE.jar
Spring-android-rest-template-1.0.0.RELEASE.jar
The usage is simple, as follows:
Multivaluemap <string, string> MVM = new linkedmultivaluemap <string, string> ();
MVM. Add ("value", value );
Map <string, string> vars = new hashmap <string, string> ();
Vars. Put ("username", username );
Vars. Put ("password", password );
Vars. Put ("key", key );
List Messageconverters. Add (New formhttpmessageconverter ());
Messageconverters. Add (New stringhttpmessageconverter ());
Resttemplate. setmessageconverters (messageconverters );
String seturl = URL
+ "Setkeybigvalue. do? Username = {username} & Password = {password} & Key = {key }";
String result = resttemplate. postforobject (seturl, MVM, String. Class, vars );
In this way, services on the server can be easily used on the Mobile End.