[英]Request method 'DELETE' not supported - reactjs + spring Boot
使用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 app中沒有關於此事件的日志消息...
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代碼的path中發送它:
url: API_BASE_URL + "/company/" + deleteCompany.companyId,
或者從spring boot @PathVariable
刪除@PathVariable
並更改以從持有String companyId
@PathVariable
對象中獲取它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.