Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringMVC请求参数转换_Java_Spring Mvc_Propertyeditor - Fatal编程技术网

Java 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

我可以使用SpringMVC中的属性编辑器对请求参数进行自定义转换。例如,将请求参数转换为下面
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