Here we introduce how to update the list array with the Post method of rest, the related concepts of rest can be referred to
http://blog.csdn.net/lfsfxy9/article/details/9205337
Since the service is provided, there must be both service side and cient side. This will use some of the classes encapsulated by the Jersey framework to showcase a rest service-style server and client.
Service side
' @POST @path ("/updatepwd") @Produces ({mediatype.application_xml, Mediatype.application_json}) @Consumes (" Application/x-www-form-urlencoded ") @SuppressWarnings ({" Unchecked "," rawtypes "}) public Response updatepwd ( Multivaluedmap<string, list<string>> UserMap) throws Serviceexception {//Checksum pass parameter if ("0". Equals (" Usermap.size ()) {Servicerevisionutils.registererror () {status_ict_err_param, "pass the required parameter to NULL error, please verify that the parameter is mandatory. Information such as the length of the parameter. "); } if (Stringutils.isempty (Usermap.get ("token"). ToString ())) {Servicerevisionutils.registererror (status_ict_err_ PARAM, "Pass the required parameter is a null error, please verify that the parameters are required to fill the non-required, parameter length and other information." "); } HashMap Accountpwdmap = new hashmap<string, string> (); List userlist=new arraylist<string> (); Userlist=usermap.get ("userlist"); for (int i=0;i<userlist.size (); i++) {string[] Users=userlist.get (i). ToString (). Split (","); Accountpwdmap.put (Users[0],users[1]); } if (userinforevisionmanager.updatepwd(Accountpwdmap)) {return Response.ok (//Status value 0 indicates a social Security number "{\" status\ ": 1, \" message\ ": \" "+ usermap.size () + "Bar Password update successful! "+" \ "}"). Build (); } else {return Response.ok (//Status value 0 indicates a social Security number "{\" status\ ": 2, \" message\ ": \" + "Password update failed to rollback please try again!) "+" \ "}"). Build (); }}`
Client Side
`public static void main(String[] args) { ClientConfig cc = new DefaultClientConfig(); Client c = Client.create(cc); MultivaluedMap form = new MultivaluedMapImpl(); form.add("token", "b310e7cb766146d28caa458fc34ed62a"); List userList=new ArrayList<String>(); userList.add("super,1"); userList.add("XPKY01SG03,2"); form.put("userList",userList); String baseUrl = "http://localhost:8080/baseconnect/rest/fieldServiceRevision/updatePwd"; WebResource wr = c.resource(baseUrl); String response = wr.post(String.class, form); System.out.println("result:" + response);}`
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Jersey Building Rest Service style