日期:2014-05-16 浏览次数:20569 次
public class FooBean {
private String name;
private Long id;
private Date birthday;
private List<Address> addresses;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public List<Address> getAddresses() {
return addresses;
}
public void setAddresses(List<Address> addresses) {
this.addresses = addresses;
}
@Override
public String toString() {
return "FooBean{" +
"name='" + name + '\'' +
", id=" + id +
", birthday=" + birthday +
", addresses=" + addresses +
'}';
}
}public class Address {
private String street;
private int number;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return "Address{" +
"street='" + street + '\'' +
", number=" + number +
'}';
}
}@RequestMapping(value="/someAction", method=RequestMethod.POST)
public String processSubmit(FooBean fooBean, Model model) {
// 利用fooBean
return “views/some_page”;
}
var data = {
name : "matianyi",
id : 12345,
birthday : "1983-07-01 01:12:12",
addresses : [
{
street : "street1",
number : 1
},
{
street : "street2",
number : 2
}
]
};@RequestMapping(value = "/fastjson", method = RequestMethod.POST)
public @ResponseBody FooBean fastjson2(@FastJson FooBean foo) {
System.out.println(foo);
return foo;
}@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FastJson {
}public class FastJsonArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
ret