Spring RequestBody - 状态415 - 简单代码不起作用

时间:2014-06-13 08:42:06

标签: json spring

大家好我有大量的简单代码:

JSON CLASS:

public class AddressJSON implements Serializable{


private static final long serialVersionUID = 341272642200865765L;

private String firstName;
private String lastName;

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}

}

控制器:

@RequestMapping(value = "/test", method = RequestMethod.POST)
@ResponseBody
public String test(HttpServletRequest request, HttpServletResponse response, @RequestBody AddressJSON addressJSON)
{

    logger.info("FIRSTNAME: "+addressJSON.getFirstName());

    return "TEST";
}

我通过chrome POSTMAN使用简单的JSON请求,如下所示:

  

{       " firstName":" test",       " lastName":" test" }

最后我得到415 ......我做错了什么也许我忘了什么?

POSTMAN REQUEST:

https://dl.dropboxusercontent.com/u/16887656/postman.PNG

1 个答案:

答案 0 :(得分:0)

问题在于您为POSTMAN客户端调用Controller的方式。 客户端缺少Content-Type: application/json HTTP标头