2011-07-06 4 views
1

SpringMVC에서 속성 편집기를 사용하여 요청 매개 변수의 사용자 정의 변환을 수행 할 수 있습니다. 예SpringMVC 요청 매개 변수 변환

public class Foo { 
    private val; 

    public Foo(String val) { 
     this.val = val; 
    }   
    public getVal() { 
     return val; 
    }  
} 

아래 Foo의 인스턴스에 요청 매개 변수를 변환하기 위해 나는 프로퍼티 에디터

public class FooPropertyEditor extends PropertyEditorSupport { 

    void setAsText(String paramValue) { 
     value = new Foo(paramValue); 
    } 

    public String getAsText() { 
     return ((Foo) value).getVal(); 
    } 
} 

을 정의하고 푸

public class CustomEditorRegistrar implements PropertyEditorRegistrar { 

    public void registerCustomEditors(PropertyEditorRegistry reg) { 
     reg.registerCustomEditor(Foo.class, new FooPropertyEditor()); 
    } 
} 
에 문자열에서 변환을 수행하려면이 옵션을 등록 할 수 있습니다

속성 편집기를 사용하여 여러 값 매개 변수 (예 :

)를 변환 할 수 있습니까?
foo=foo1&foo=foo2&foo=foo3 

~ List<Foo>. 이미 적절한 속성 편집기 FooListPropertyEditor를 작성한 가정하면, 내가 사용하여 등록 할 수 있다고 생각하지 않습니다 :

public void registerCustomEditors(PropertyEditorRegistry reg) { 
    reg.registerCustomEditor(List<Foo>.class, new FooListPropertyEditor()); 
} 

AFAIK List<Foo>.class

답변

0

org.springframework 살펴보고 올바른 구문이 아니기 때문에. beans.propertyeditors.CustomCollectionEditor