0

Ui code is

    var page1={"name":"raj","acc":"123"};
    var page2={"name1":"sathi","acc2":"321"};

    var finl={"page1":page1,"page2":page2};

    var response=$http.post("myfirsturl",{"page1":page1,"page2":page2});

spring controller code is

    @RequestMapping(value="/myfirsturl",method=RequestMethod.POST)
public String hello1(@RequestBody sampledetails details){

    page1 obj=details.getPag1();
    page2 obj2=details.getPag2();

    System.out.println(obj.getName()+"  "+obj.getAcc());
    System.out.println(obj2.getName1()+"  "+obj2.getAcc2());


    return "";
}

sampledetails class

  public class sampledetails implements Serializable{


  private page1 pag1;
   private page2 pag2;

   //setters and getters

page1 class

 public class page1 implements Serializable{

  private String name;
  private String acc;
  //setters and getters

page2 class public class page2 implements Serializable{

  private String name1;
  private String acc2;
  //setters and getters

I have tried sending object it is working for primitive types but not working for objects.

1
  • Is there any solution?? Commented Jan 22, 2016 at 12:54

1 Answer 1

1

It's pag1 not page1 acccording to your sampledetails bean class. You must use member variable name.

Change this

var response=$http.post("myfirsturl",{"page1":page1,"page2":page2});

To this

var response=$http.post("myfirsturl",{"pag1":page1,"page2":pag2});

Or like this

$http.post('/myfirsturl', {         
            "pag1" : page1, "pag2" : page2
        }).success(function(data){
            alert("Success");
        })

Controller

@RestController
public class Controller {

     @RequestMapping(value="/myfirsturl",method=RequestMethod.POST)
     public String hello1(@RequestBody Sampledetails details){

         System.out.println("Inside");

         Page1 obj=details.getPag1();
         Page2 obj2=details.getPag2();

         System.out.println(obj.getName()+"  "+obj.getAcc());
         System.out.println(obj2.getName1()+"  "+obj2.getAcc2());


         return "";
     }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.