Я новичок в весне и отдыхе. Я написал простой отдых, как это:Отсутствует Требуемый объект запроса
@RequestMapping(value = "/loginTest", method = RequestMethod.POST)
@ResponseBody
public Response loginTest(@RequestBody LoginRequest request) {
System.out.println("enter loginTest.");
String account = request.getAccount();
String password = request.getPassword();
Response res = new Response();
return res;
}
И LoginRequest как это:
public class LoginRequest {
private String account;
private String password;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Когда я проверить это с помощью команды:
curl -X POST "{"account": "aaa","password": "bbb"}" -H "Content-type:application/json" http://localhost:8080/user/loginTest
Но я получил результат:
[1/2]: account: aaa --> <stdout>
--_curl_--account: aaa
curl: (6) Could not resolve host: account; nodename nor servname provided, or not known
{
"timestamp" : "2015-12-30T16:24:14.282+0000",
"status" : 400,
"error" : "Bad Request",
"exception" : "org.springframework.http.converter.HttpMessageNotReadableException",
"message" : "Bad Request",
"path" : "/user/loginTest"
}
А также в консоли Eclipse:
Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public com.test.response.Response com.test.service.UserService.loginTest(com.test.model.request.LoginResquest)
ли класс LoginRequest нужна аннотация? Потому что Джейсон не может быть преобразован в класс? Помогло бы мне понять это?
Как насчет ошибки «Не удалось разрешить хост». Вы сначала попытались исправить эту часть? – Duston
Нажмите [здесь] (https://stackoverflow.com/questions/29223683/required-request-body-content-is-missing-org-springframework-web-method-handler/45748010#45748010)! Это сработало для меня. [блог] [блог]: https://stackoverflow.com/questions/29223683/required-request-body-content-is-missing-org-springframework-web-method-handler/45748010#45748010 –