小编Nik*_*hav的帖子

春季启动-请求方法'POST'不支持。尝试了一切

我正在使用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)

java spring spring-mvc spring-boot

2
推荐指数
2
解决办法
4万
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-mvc ×1