Angular 触发HTTP客户端的HTTP Delete send-服务器未接收

Angular 触发HTTP客户端的HTTP Delete send-服务器未接收,angular,spring,http,Angular,Spring,Http,我正在开发一款包含CRUD功能的应用程序。我使用Spring作为后端实现,使用Angular作为前端实现。在前端,我像这样使用Angular的http客户端来删除一个实体(为了简洁起见,以下代码被缩短): 组成部分: export class RecipeComponent implements OnInit { constructor(private recipeService : RecipeService) { } deleteElement (id : number) {

我正在开发一款包含CRUD功能的应用程序。我使用Spring作为后端实现,使用Angular作为前端实现。在前端,我像这样使用Angular的http客户端来删除一个实体(为了简洁起见,以下代码被缩短):

组成部分:

export class RecipeComponent implements OnInit {

  constructor(private recipeService : RecipeService) { }

    deleteElement (id : number) {
        this.recipeService.deleteRecipe(id).subscribe();
    }
}
服务:

export class RecipeService {

    deleteRecipe (id : number) : Observable<{}> {
      return this.http.delete('http://localhost:8080/recipe/' + id);
    }

  constructor( private http: HttpClient ) { }
}
但是,我的后端没有收到请求。奇怪的是,张贴或获得工作的罚款

谁能给我指一下正确的方向吗


谢谢你,祝你好运

400错误请求很可能是“body is missing”错误。从方法参数中删除
@RequestBody Recipe deletedRecipe
,因为您没有提供要删除的实体,
id
就足够了。

如果您通过curl发送请求,是否有效<代码>卷曲-vSX删除http://localhost:8080/recipe/id?它返回
400
,这意味着请求不正确。你确信你在春天的实现吗?你能分享一下吗?所以,curl日志是:
*尝试127.0.0.1…*TCP#U节点延迟设置*连接到本地主机(127.0.0.1)端口8080(#0)>删除/recipe/301 HTTP/1.1>主机:本地主机:8080>用户代理:curl/7.58.0>接受:*>
,这对我帮助不大-实体仍然存在。当我以邮递员的形式发送请求时,实体被删除了,我把问题中的重要部分放在上面。就这样!我在需要控制器之前很久就编写了它,但忘记了这一点。
@ControllerAdvice
@CrossOrigin(origins = "http://localhost:4200")
@RequestMapping(path="/recipe")
public class RESTController {
    @Autowired
    private RecipeRepository recipeRepository;


@DeleteMapping(path="/{id}")
public @ResponseBody ResponseEntity deleteRecipe (@RequestBody Recipe deletedRecipe, @PathVariable("id") int id) {

    try {
        [...]
        }
    } catch (RecipeNotFoundException e) {
        [...]       
    }
}


}