1
这是关于Spring属性编辑器的。 我正在被实现为B类和C 我有一个命令类文件,其中,其中我有一个春季注册自定义属性编辑器
class Doc{
List<A> list ;
}
列表的列表可能包含B或C中的任一个对象接口A在这种情况下,我该如何使用属性编辑器。我写了两个类2的属性编辑器,并在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
这是我的第一篇,请对不起,如果我没有犯错。
只是猜测的一个实例,但因为你有一个List ,你怎么了期待Spring填充它?使用Bs还是Cs? –
A是一个接口... B和C是它的实现类,所以List可以包含B或C的对象。 –
我明白这一点。但如果你不关心Spring是否将B或C实例放入列表中,那么有两种不同的实现有什么意义? –