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實例放入列表中,那麼有兩種不同的實現有什麼意義? –