spring-boot - 如何解决 React 中的错误请求错误 400?
问题描述
当我将此请求从 Postman 发送到 SpringBoot 时,它可以工作。
"location": "New Jersey",
"category": {
"name": "Travel",
"id": 1
},
"expensedate": "2020-03-17",
"descript": "New York City"
}
但是,当我从 ReactJS 发布请求时,它显示400 Bad Request
const item1={
descript : event.target.description.value,
category:{
id:1, name:event.target.category.value
},
expensedate : event.target.date.value,
location : event.target.location.value
}
console.log(event.target.category.key);
console.log(item1)
await fetch(`/api/expenses`, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8'},
body: JSON.stringify(item1)
})
SpringBoot
@PostMapping("/expenses")
Expense createExpense(@RequestBody Expense expense){
return this.expenseRepository.save(expense);
}
解决方案
推荐阅读
- vector - 两个 N 维向量之间的旋转方向(符号)/角度
- c++ - 向量的 std::copy 无法正常工作
- javascript - 无法读取未定义的属性“地图”(尝试从 API 获取)
- flutter - 如何将相同的小部件传递给块构建器中的所有状态
- php - 使用模态提高 PHP 中嵌套包含的性能
- css - 如何在 Ionic 5 中更改 SVG 填充颜色
- edgar - 下载多个 10-ks 文档
- elasticsearch - 从嵌入式弹性搜索中休息高级客户端
- user-input - 是否有以“.con”结尾的电子邮件地址?
- php - 如何停止更改 acf 字段(日期时间选择器/Wordpress)中的日期和时间?