java - 异常:org.springframework.web.HttpRequestMethodNotSupportedException 使用 Spring post 方法时
问题描述
我有以下代码在我的控制器中映射发布 API。我已经为 POST 请求参数定义了一个模型。
public class CreateUserBody {
String CandidateId = "";
String EmployeeId = "";
String CompanyId = "";
public String getCandidateId() {
return CandidateId;
}
public String getEmployeeId() {
return EmployeeId;
}
public String getCompanyId() {
return CompanyId;
}
}
当我触发这个 API 时,我得到了 HttpRequestMethodNotSupportedException。请帮我解决这个问题。
@RequestMapping(value = "/SetEmployeeIdOneByOne/", method = RequestMethod.POST)
public @ResponseBody void SetEmployeeIdOneByOne(@RequestBody CreateUserBody createUserBody) throws Exception{
String CandidateId = createUserBody.getCandidateId();
String EmployeeId = createUserBody.getEmployeeId();
String CompanyId = createUserBody.getCompanyId();
SetEmployeeID.SetEmployeeIDOneByOneInteger(CandidateId, EmployeeId, CompanyId);
}
我正在调用 API,例如...
解决方案
而不是将数据放入form-data
发布您的数据raw
,然后选择内容类型为application/json
. 在正文中,您的数据应如下所示:
{
"CandidateId":"3",
"EmployeeId":"5696969",
"CompanyId":"15272"
}
您在邮递员中请求的网址应如下所示:
http://localhost:9199/SetEmployeeIdOneByOne/
推荐阅读
- c++ - 如何使用 C++ 原子
- asp.net - ASP.NET 无法连接到同一台计算机上的 SQL Server 数据库
- php - 按产品名称获取 WooCommerce 的产品 ID
- c - 如何使用 C 从 .txt 文件的特定点读取整数?
- matlab - 我如何输入一个函数并在句柄函数中使用它
- php - PHP stream_socket_enable_crypto 无限期挂起。无论如何要修复?
- java - 如何使用mockito测试从静态值作为参数调用另一个void函数的函数
- reactjs - 反应钩子和 setInterval
- android - 适用于 Android 的 Tello Video Stream API
- php - 在一个字符串中拆分多个图像