Reading json data in spring controller sent by angular 2 post -
i find solution think there easier way. trying post json data using angular2 , try read in spring controller.
class
export class emoviecat{ id:string = "test"; rev:string; datamodelversion:number = 99; }
post code in angular 2
this.emv = new emoviecat(); this._http.post(this._url,json.stringify(this.emv)).subscribe(response =>{ console.log(response.json()); });
i getting json string this.
bufferedreader br = null; try { br = new bufferedreader(new inputstreamreader(this.req.getinputstream())); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } string json = ""; if(br != null){ try { json = br.readline(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } }
this way can json string. in advance
you should kind of controller:
@requestmapping(method ={ requestmethod.post }, value ={ "/save/info" }, produces = { "application/json" }) public responseentity<string> storeredirecturl(@requestbody emoviecat emc) { //here have emc object json reversed in java object }
in case spring able in creating emoviecat object using jackson marshaller api , must take care business logic
Comments
Post a Comment