【发布时间】:2015-12-30 17:04:21
【问题描述】:
我是 Spring and Rest 的新手。 我像这样写了一个简单的休息:
@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 类是否需要注解?因为 Jason 不能转换为类? 有人能帮我解决这个问题吗?
【问题讨论】:
-
“无法解析主机”错误怎么办。您是否尝试过先修复该部分?
-
点击here!这对我有用。 [博客] [博客]:stackoverflow.com/questions/29223683/…
标签: java spring restful-url