将从附加表单获取的值发送到spring控制器
我正在创建一个模型,其中结构如下:将从附加表单获取的值发送到spring控制器,spring,model-view-controller,Spring,Model View Controller,我正在创建一个模型,其中结构如下: public class A { private Long id; private Type type; private Set<String> names; private Set<Long> ids; private Set<String> subnames; private Set<Long> subids; ........... } 公共A类{ 私人长id; 私有类型; 私有集合名; 私
public class A {
private Long id;
private Type type;
private Set<String> names;
private Set<Long> ids;
private Set<String> subnames;
private Set<Long> subids;
...........
}
公共A类{
私人长id;
私有类型;
私有集合名;
私有集标识;
私有集子名称;
私有集合子ID;
...........
}
我想创建一个模型,有多个我喜欢的字段。
因此,我创建了如下表单以动态添加新行
Creation Form: One of the fields-->
<form>
<div id="addNewname" class="form-group">
<label>name</label>
<div class="col-lg-4">
<input type="text" name="name_1" id="name" readonly>
</div>
<button id="btnAddname" type="button"
type="hidden"
value="btnAddName" name="btnAddName">Add
New</button>
</div></form>
创建表单:其中一个字段-->
名称
添加
新的
使用脚本添加新内容,如下所示:
public class A {
private Long id;
private Type type;
private Set<String> names;
private Set<Long> ids;
private Set<String> subnames;
private Set<Long> subids;
...........
}
整数计数=1
$(document).on("click", "#btnAddNew", function(){
count++;
$('#addNewNew').after(
'<div>' +
'<label> New Name</label>'+
'<div >' +
'<select name="name_'+ count +'">'+
'<option value="0">None</option>' +
'<c:forEach items="${names}" var="name">' +
'<option value="${name.id}">${name.name}</option> '+
'</c:forEach>'+
'</select>'+
'</div>'+
'</div>');
});
$(文档)。在(“单击”上,“#btnAddNew”,函数(){
计数++;
$('#addNewNew')。之后(
'' +
“新名字”+
'' +
''+
“没有”+
'' +
“${name.name}”+
''+
''+
''+
'');
});
我能够将该值发送到定义表单的value name=“name_1”的控制器,但无法对从append form--script创建的值执行相同的操作
任何解决这个问题的想法或建议,我都尝试过很多方法,但是…您可以使用LazyList添加任意数量的名称 在命令类中,不要使用Set来定义名称,请尝试以下操作:
import org.apache.commons.collections.FactoryUtils;
import org.apache.commons.collections.list.LazyList;
。。。
private List name=LazyList.decoration(新ArrayList(),
instancefactory(String.class));
在Jsp页面中,所需要的只是使用arrayIndex来访问或绑定值。即
在javascript中,执行相同的操作,在动态创建更多文本输入时使用arrayIndex