我正在使用
Content-Type
作为 application/x-www-form-urlencoded
发出 PUT 请求。我无法将表单主体元素映射到我的 ModelDriven
操作类 User
。
这是一个示例请求:
PUT: http://www.example.com/account/22424?userName=xyz&[email protected]
Content-Type: application/x-www-form-urlencoded
这是代码:
1)
Modeldriven
动作类别:
public class User {
private String email;
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
2)控制器:
public class AccountController implements ModelDriven <User> {
private String id;
private User user = new User();
public String update() {
user.getUserName(); // Fails, returns NULL. (Expected "xyz")
}
public User getModel() {
return user;
}
}
如有任何建议,我们将不胜感激。