我正在使用Spring Boot和MongoDB构建一个Web应用程序,它将仅对员工文档执行CRUD操作。
"Request method 'POST' not supported"当我尝试使用json命中create employee端点时出现此错误。
我的控制器类是:
@RestController
@RequestMapping("/employeeapp/employees")
public class EmployeeController {
private final EmployeeService service;
@Autowired
public EmployeeController(EmployeeService service) {
this.service = service;
}
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public
@ResponseBody
Employee create(@RequestBody @Valid Employee employeeEntry) {
return service.create(employeeEntry);
}
@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
public Employee delete(@PathVariable("id") long id) {
return service.delete(id);
}
@RequestMapping(method = RequestMethod.GET)
public List<Employee> findAll() {
return service.findAll();
}
@RequestMapping(value = "{id}", method = RequestMethod.GET)
public Employee findById(@PathVariable("id") long id) …Run Code Online (Sandbox Code Playgroud)