How to send complex JSON structure from angular to spring controller


wcf
26/4/2016 6:52 am
HOME ยป Web Development

I've a JSON like below in my angular controller, which i need to post to Spring controller.

var items={"A":"aa",
           "B":"bb",
           "C":{"D":"dd", "E":"ee"}
           };

$http.post('localhost:8082/ProjectName/posting',items)
.success(function(data,status,headers, config){
   alert("success");
})
.error(function(error){
    alert(error);
});

In my Spring controller

@RestController
public class ForPost{
  @RequestMapping(value="/posting",method=RequestMethod.POST)
  public @ResponseBody List  forPosting(@RequestBody PostingModel
postingModel){
    System.out.println("Print all values received");
    .
    .
    .
    .
  }
}

I'm thinking for this kind of nested JSON, I need to have nested POJO. something like:

public class PostingModel{
 String A;
 String B;
 POJOForC C;
 /* getter setter below*/
}

puublic class POJOForC{
 String D;
 String E;
 /* getter setter below*/
}

I get error message: The request sent by client was syntactically incorrect(). Am I accepting the values correctly? Need to fix something in POJO?


Related to : How to send complex JSON structure from angular to spring controller
How to send complex JSON structure from angular to spring controller
26/4/2016 6:52 am Web Development

I've a JSON like below in my angular controller, which i need to post to Spring controller.

var items={"A":"aa",
           "B":"bb",
           "C":{"D":"dd", "E":"ee"}
           };

$http.post('localhost:8082/ProjectName/posting',items)
.success(function(data,status,headers, config){
   alert("success");
})
.error(function(error){
    alert(error);
});

In my Spring controller

@RestController
public class ForPost{
  @RequestMapping(value="/posting",method=RequestMethod.POST)
  public @ResponseBody List  forPosting(@RequestBody PostingModel
postingModel){
    System.out.println("Print all values received");
    .
    .
    .
    .
  }
}

I'm thinking for this kind of nested JSON, I need to have nested POJO. something like:

public class PostingModel{
 String A;
 String B;
 POJOForC C;
 /* getter setter below*/
}

puublic class POJOForC{
 String D;
 String E;
 /* getter setter below*/
}

I get error message: The request sent by client was syntactically incorrect(). Am I accepting the values correctly? Need to fix something in POJO?


JSON - Spring MVC : How to post json data to spring MVC controller
Web Development

I have a problem posting JSON data from jsp to controller. Everytime I try I get an ajax error Bad Request. Im so new to JSON and I really don't know what I am doing wrong. I searched and tried some samples I can find in this site but still Im having a problem.


In my controller:


@RequestMapping (method = RequestMethod.POST, headers ={"Accept=application/json"}, value = "/form")
public String postJournalEntry (@RequestParam ("json") String json, Model model) {
System.out.println(json);
return "successfullySaved";
}

In my jsp:


JQuery/Spring: Posting json object to spring controller not working
Web Development

This is my spring controller


@RequestMapping(value = "/app/{appId}/save.html",method=RequestMethod.POST)
public @ResponseBody String myFunction
(@PathVariable("appId") String id, @RequestBody Map<String, String> data1) {
return "hello";
}

This is my ajax request


$.ajax({
type : 'POST',
url : '/app/${param.appID}/save.html',
data : JSON.stringify(myJsonData),
dataType : "json",
success : function(data, textStatus,

Angular controller structure for multipart view
30/12/2014 4:00 pm Web Development

layout

I need to create this layout in a SPA using AngularJS and a web api. The workflow goes as follows:

  1. When the controller loads, two sets of data get fetched from the api (table above and table to the left - e.g. 2 calls to api/data1 and api/data2)
  2. As soon as the user clicks a row in the upper table, detail information gets fetched into the box on the right side (api/data1/3434/detail)
  3. When the user clicks on certain entries from the detail information box, the related entries are being highlighted in the table to the left.

I started creating a view with everything in it, also a controller that exposes properties for all necessary stuff, but now it looks like this (pseudo)

myPageController
    table1Data : Array<IData1Model>;
    table2Data : Array<IData2Model>;
    userSelectedFromTable1 : IData1Model;
    userSelectedFromTable2 : IData2Model;

I feel this isn't really good practice. Is there a way to suborganize the parts into some kind of partial views? Subcontrollers? Or is this a common approach? What does the usual controller looks like when he's going to serve for multiple kinds of data / api endpoints?


EDIT

I should clarify that this is just one particular page (section) of a bigger app. Most parts are just frontends for one kind of data, e.g. one controller, one model, one api call etc. Think of the page as some kind of dashboard where multiple data is shown and interact with each other.




HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .