java - How to pass multiple parameters to Jersey POST method -
i trying pass multiple parameters jersey post method . following below steps pass single parameter jersey post method.
client client = clientbuilder.newclient(); webtarget target= client.target("http://localhost:8080/rest/rest/subuser").path("/insertsubuser"); subuserbean subuserbean=new subuserbean(); subuserbean.setiduser(1); subuserbean.setidsubusertype(1); subuserbean.setidsubuser(15); subuserbean.setfirstname("haritha"); subuserbean.setlastname("wijerathna"); subuserbean.setnumberofdaystoeditrecord(14); subuserbean.setusername("haritha"); subuserbean.setpassword("hariwi88"); subuserbean.setdatecreated(common.getsqlcurrenttimestamp()); subuserbean.setlastupdated(common.getsqlcurrenttimestamp()); target.request(mediatype.application_json_type).post(entity.entity(subuserbean, mediatype.application_json_type));
subuserjsonservice.java
@path("/subuser") public class subuserjsonservice { @post @path("/insertsubuser") @consumes(mediatype.application_json) public string updatesubuser(subuserbean bean){ subuserinterface table = new subusertable(); string result= table.insertsubuser(bean); return result; } }
now, want pass parameters following method via jersey post method.
public string inserthistory(list<socialhistorybean> list, string comment){ //my stuffs }
have ideas above work ?
thank you.
you can try using multivaluedmap.add form data , send server. example below, code not tested demo/logic flow.
webtarget webtarget = client.target("http://www.example.com/some/resource"); multivaluedmap<list, string> formdata = new multivaluedhashmap<list, string>(); formdata.add(list, "list1"); formdata.add("key2", "value2"); response response = webtarget.request().post(entity.form(formdata));
consume on server side like
@path("/uripath") @post -- if post or @get @consumes("application/x-www-form-urlencoded;charset=utf-8") or json.. @produces("application/json") public void methodnamehere(@formparam("list") list<string> list1, @formparam("key2") string val2) { system.out.println("here am"); system.out.println("list1" + list1.size); system.out.println("val2" + val2); }
read more here in docs..
Comments
Post a Comment