1

这是关于 Spring 属性编辑器的。我有一个正在为 B 类和 C 类实现的接口 A。我有一个命令类 Doc,其中我有一个 A 列表

class Doc{
List<A> list ;
}

列表可能包含 B 或 C 的对象。在这种情况下,我如何使用属性编辑器。我为这两个类编写了两个属性编辑器,并将它们注册为 initBinder 方法

binder.registerCustomEditor(C.class,new CPropertyEditor());
 binder.registerCustomEditor(B.class,new BPropertyEditor()); 

但它似乎没有工作。请帮忙。

我收到以下异常:

Request processing failed; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.test.A] for property list: no matching editors or conversion strategy found

这是我的第一篇文章,如果我犯了任何错误,请见谅。

4

1 回答 1

0

一种方法是为 A 实现单个属性编辑器。实现可以查看字符串,然后创建 B 或 C 的实例。

于 2011-11-29T10:04:01.730 回答