Java SpringMVC请求参数转换
我可以使用SpringMVC中的属性编辑器对请求参数进行自定义转换。例如,将请求参数转换为下面Java SpringMVC请求参数转换,java,spring-mvc,propertyeditor,Java,Spring Mvc,Propertyeditor,我可以使用SpringMVC中的属性编辑器对请求参数进行自定义转换。例如,将请求参数转换为下面Foo的实例 public class Foo { private val; public Foo(String val) { this.val = val; } public getVal() { return val; } } 我可以定义属性编辑器 public class FooPropertyE
Foo
的实例
public class Foo {
private val;
public Foo(String val) {
this.val = val;
}
public getVal() {
return val;
}
}
我可以定义属性编辑器
public class FooPropertyEditor extends PropertyEditorSupport {
void setAsText(String paramValue) {
value = new Foo(paramValue);
}
public String getAsText() {
return ((Foo) value).getVal();
}
}
并注册它以执行从字符串到Foo的转换
public class CustomEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry reg) {
reg.registerCustomEditor(Foo.class, new FooPropertyEditor());
}
}
是否可以使用属性编辑器转换多值参数,例如
foo=foo1&foo=foo2&foo=foo3
到列表
。假设我已经编写了一个适当的属性编辑器愚人属性编辑器
,我想我无法使用以下方法注册它:
public void registerCustomEditors(PropertyEditorRegistry reg) {
reg.registerCustomEditor(List<Foo>.class, new FooListPropertyEditor());
}
public void register客户编辑器(PropertyEditorRegistry reg){
reg.registerCustomEditor(List.class,新的傻瓜属性编辑器());
}
因为AFAIK
List.class
语法无效请查看org.springframework.beans.propertyeditors.CustomCollectionEditor