Request method 'GET' not supported, Method Not Allowed 405()
当我在我的控制器类中使用@DeleteMapping 时,我得到了上述类型的错误首先我没有在我的DeleteMapping 中使用“路径”我直接提供了我的路径,然后我得到了同样的错误为什么会出现这种类型的错误。请提及此类错误的主要原因是什么以及解决方案 Controller.java 是什么
package com.main.AngBoot.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.main.AngBoot.bean.Product;
import com.main.AngBoot.service.ProductHardcodedService;
@CrossOrigin(origins="http://localhost:4200")
@RestController
public class ProductController {
@Autowired
private ProductHardcodedService prodService;
@GetMapping("/users/{productname}/prodct")
public List<Product> getAllProducts(@PathVariable String productname){
return prodService.findAll();
}
@DeleteMapping(path="/users/{productname}/prodct/{id}")
public ResponseEntity<Void> deleteProduct(@PathVariable String productname,
@PathVariable long id){
Product product = prodService.deleteById(id);
if (product != null) {
return ResponseEntity.noContent().build();
}
return ResponseEntity.notFound().build();
}
}

