我有一个宁静的服务,我想用Angular 4的HTTP / GET服务来调用这些服务。但是在我的服务中使用params,我不知道如何做到这一点。
Java代码:
@GET
@Path("/typeOfDemandByCode/{code}")
@Produces(MediaType.APPLICATION_JSON)
public String getLabelByCode(@PathParam(value="code") String code) {
return administrationsBusiness.getLabelByCode(code);
}
我的service.ts(我使用RequestOptions)
getLabelTypeOfDemandByCode(code: string) {
let myHeader = new Headers();
myHeader.append('Content-Type', 'application/json');
let myParams = new URLSearchParams();
myParams.set('code', code);
let options = new RequestOptions({ headers: myHeader, params: myParams });
return this.http.get('/CCPDWebService/administration/typeOfDemandByCode', options)
.map((response) => {
return response.text() ? response.json() : [{}];
})
}
component.ts
getLabelTypeOfDemandByCode(code : string) {
return this.adminService.getLabelTypeOfDemandByCode(code).subscribe(
labelTypeOfDemand => {
this.labelTypeOfDemand = labelTypeOfDemand;
});
}
saveFolder() {
// Here I do a test for getting value
console.log(this.getLabelTypeOfDemandByCode("BGS"));
}
但是当我试图用“params代码”获取我的列表值时,我在我的控制台中找到了这一行:
Subscriber {closed: false, _parent: null, _parents: null, _subscriptions: Array(1), syncErrorValue: null, …}
GET http://localhost:4200/CCPDWebService/administration/typeOfDemandByCode 404 (Not Found)
我的JSON喜欢:
{
"id": 9,
"code": "BGS",
"label": "TEST",
"status": null
},
{
"id": 7,
"code": "PBA",
"label": "TEST",
"status": null
},
{
"id": 8,
"code": "KBA",
"label": "TEST",
"status": null
}