的对象获取它
使用reactjs和springboot应用...传递值通过JSON获取错误:
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'DELETE' not supported]
尝试了这两个选项。
1。
@DeleteMapping("/{companyId}")
public Long deleteCompany(@PathVariable Long companyId)
2。
@RequestMapping(value = "/{Company}",method=RequestMethod.DELETE)
public @ResponseBody void deleteCompany(
@PathVariable("companyId") Long companyId){
来自React:
export function RemoveCompany(deleteCompany) {
alert(deleteCompany.companyId);
return request({
url: API_BASE_URL + "/company",
method: 'delete',
body: JSON.stringify(deleteCompany)
});
}
in springboot app
```@DeleteMapping(value="company/{companyId}")
public @ResponseBody void deleteCompany(
@PathVariable("companyId") Long companyId){
System.out.printf("Testing: You tried to delete n");
}
=======================以下是ReactJS代码错误。Message返回"无消息"。在Spring Boot应用程序中,此事件没有日志消息...
RemoveCompany(deleteCompany)
.then(response => {
notification.success({
message: 'company soft',
description: "Thank you! Company Created Successfully!",
});
this.props.history.push("/company");
}).catch(error => {
notification.error({
message: 'company soft',
description: error.message || 'Sorry! Something went wrong. Please try again!'
});
});
您不是按照预期的路径发送公司,而是在身体中,
您可以在React代码中以路径发送:
url: API_BASE_URL + "/company/" + deleteCompany.companyId,
或从Spring Boot @PathVariable
中删除CompanyId,然后更改以从持有String companyId