使用 springMVC 请求Action 返回400编码
环境:j2ee web网站,使用spring MVC框架,页面时间选择控件使用的是 easyui-datebox
问题描述:
在请求指定 action方法时,方法参数为自定义类型
public class Person {
private Integer id;
private String name;
private Integer age;
private Date birth;
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
当运行网站,在浏览器上填写用户数据时候,选择生日日期。提交数据后提示400错误请求。
问题跟踪:
尝试了在浏览器地址直接填写请求数据,没有日期数据是正确显示的。
问题解决:
统一前台和后台的时间格式,实体对象可以指定格式:例如:@DateTimeFormat(pattern = "yyyy-MM-dd") 或者其他时间格式。
备注:有任何问题,请多多指教!
热爱编程,热爱生活!