0

私は動的にフォームを作成しています、そしてそれを投稿してSpringControllerで値を取得する必要があります

    for(var i=0;i<datArray.length;i++){
        element[i] = document.createElement("input");
        element[i].setAttribute("type", "text");
        element[i].setAttribute("name", "text");
        element[i].setAttribute("placeholder",datArray[i]);
        element[i].setAttribute("id", datArray[i]+"id");
        var foo = document.getElementById("fooBar");        
        //Append the element in page (in span).
        foo.appendChild(element[i]);
}   

これは、Select onChange で描画された動的フォームです。

About Pic - これは Select onChange で描画された私の動的フォームです

ドロップダウンが変更されるたびに、さまざまなテキスト ボックスを動的に生成しています。ダイナミック テキスト ボックスを投稿し、JAVA の Controller Spring で値を取得する必要があります。コントローラーで動的に投稿された値を取得する方法は?

何か案が?

4

1 に答える 1

3

常に同じモデル オブジェクトを送信していますか? つまり、フォーム要素は常に同じ name 属性を持っていますか?

はいの場合は、名前に一致する属性を持つ pojo クラスを作成し、RequestAttribute注釈を使用できます。

いいえの場合、方法はありません。古い requestparameter を使用する必要があります。

更新 どのパラメーターが送信されているかわからない場合は、すべてのパラメーターにループします。

    List<String> requestParameterNames = Collections.list((Enumeration<String>) request.getParameterNames());

for (String parameterName : requestParameterNames) {
    String attributeName = parameterName;
    String attributeValue = request.getParameter(parameterName);

    //DO YOUR STUFF
}
//DO YOUR STUFF
于 2013-10-01T14:25:25.323 に答える