1

サブクラス オブジェクトを jsp ビューからコントローラに返す方法。ページは、サブクラス要素を含む適切な動物リストを受け取ります。子クラス要素を表示することはできますが、それをコントローラーに送り返そうとすると、バインディング エラーが発生します。これは私の問題のモックコードです。

   public class Group
    {
    public List<Animal> animals;
    //getters and setters 
    }


    abstract class Animal
    {
    String name;
    //getters and setters 
    }

    class Lion extends animal
    {
    String legs;
    //getters and setters 
    }

私の見解:

<form:hidden path="groups[${groupssList.index}].animals[${animalsList.index}].name"/>

例外:

Could not instantiate property type [Animal] to auto-grow nested property path: java.lang.InstantiationException
4

1 に答える 1

0

あなたのpath値はnull参照になり、Springはそれにデフォルトのオブジェクトを入力しようとします。このデフォルトの動作を無効にするには、(それぞれの)@Controllerクラスに追加します。

@InitBinder
public void initBinder(WebDataBinder binder){
    binder.setAutoGrowNestedPaths(false);
}

最終的に別の例外が発生しますが、より明確になります。

于 2013-10-21T15:49:26.730 に答える