使用 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代码error.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!'
});
});
最佳答案
您没有按预期在路径中发送companyId,而是在正文中发送,
您可以在 React 代码中将其发送到路径中:
url: API_BASE_URL + "/company/" + deleteCompany.companyId,
或者从 Spring Boot @PathVariable
中删除 companyId 并更改为从持有 String companyId
的对象中获取它
关于java - 请求方法 'DELETE'不支持-reactjs + spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56749158/