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);
相關文章
相關標籤/搜索