【发布时间】:2018-06-08 23:44:35
【问题描述】:
如您所知,put 请求如下所示:
put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>
所以在我的情况下,它看起来像这样:
updateIntervention(id:number,idDev:number){
if(this.authService.getToken()==null) {
this.authService.loadToken();
}
return this.http.put(this.host+"/updateIntervention/"+id,idDev,{headers:new HttpHeaders({'Authorization':this.authService.getToken()})});
}
所以在 spring-data(back end) 中,等待 PUT 请求的方法应该是这样的,例如:
@RequestMapping(value="/updateIntervention/{id}",method = RequestMethod.PUT)
public Intervention update(@PathVariable Long id , @RequestBody B obj){
...
}
所以这里的 obj 是 B 类的对象,它具有 Long 类型的属性,它将返回 angular5 发送的 PUT 请求的主体。
我的问题是我一直在 spring-data 中创建这些不同的类(因为有时我在 body 中只发送一个属性,这就是为什么我创建一个新类来表示它)所以我可以得到由 angular 发送的 body 甚至认为它仅包含一个属性,如本例中的 idDev。
有没有更好的方法来避免在 spring-data 中创建新类,所以我无法在 body 中获取前端发送的 idDev?
如果我只是举例:
public Intervention update(@PathVariable Long id , @RequestBody long idDev){
我得到反序列化等错误..
有什么想法还是不可能?
【问题讨论】:
标签: java spring spring-data angular5