angular2与springMVC请求传递参数

springMVC 使用对象做为入参时,默认是使用request 参数的,此时须要使用 url?params=xx 的请求方式,java

这是使用 angular2 的方式为:spring

let reqHeaders = new Headers({'Content-Type': 'application/x-www-form-urlencoded'});

return this.http
            .post(this.heroesUrl, "email=eeee&id=1111", options)
            .toPromise()
            .then(res => res.json())
            .catch(this.handleError);

 

若是须要使用json方式传递参数,则在springMVC的对象前加上 @RequestBody,json

let reqHeaders = new Headers({'Content-Type': 'application/json'});

return this.http
            .put(this.heroesUrl, JSON.stringify(jso), options)
            .toPromise()
            .then(res => res.json())
            .catch(this.handleError);
相关文章
相关标签/搜索