【发布时间】:2019-09-30 07:05:57
【问题描述】:
在我的 Spring Boot 应用程序中,我有一个这样定义的端点:
startFunctionality(@PathVariable Long clientId,@PathVariable Long projectId,@PathVariable Long functionalityId, @RequestBody(required=false) Map<String,Object> variables )
我想从 Angular 传递一个地图。我是这样创建的:
let variables = new Map();
variables.set("A",1);
variables.set("B",2);
然后我以这种方式创建我的请求:
let data = {
"variables":variables
}
const request: HttpRequestInterface = {
apiUrl: 'clients/' + clientId + '/projects/' + projectId + '/functionalities/' + functionalityId + '/start',
body: data
};
return this.httpService.get(request);
get 请求是这样的:
public get(httpRequest: HttpRequestInterface): Observable<any> {
const options = this.getBaseOptions(httpRequest);
const observable = this.httpClient.get(this.apiBaseUrl + httpRequest.apiUrl, options);
return observable.pipe(
retryWhen((errors: any) => this.handleErrorsOnRequest(errors)),
map((response: any) => this.getResponseData(response))
);
}
由于不需要variables 请求正文,我在端点的方法内部执行检查。问题是,即使我用变量设置主体,端点也会收到 null。如果我尝试使用 Postman 发送变量,端点会正确接收它们,它们不为空。
【问题讨论】:
-
请求 url 正确,它与其他类型的数据一起使用。我必须改变什么?什么不合适?
标签: angular typescript spring-boot http