[英]how to get dynamic values from posting a form in the Spring controller
I am creating a form dynamically, and I need to post it and get the values in SpringController 我正在动态创建一个表单,我需要发布它并在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]);
}
About Pic - this is my dynamic form drawn in Select onChange 关于Pic-这是我在Select onChange中绘制的动态表单
On Every dropdown Changed I am generating different text boxes dynamically. 在每个下拉列表更改时,我正在动态生成不同的文本框。 I need to post the dynamic text boxes and get the values in the Controller Spring in JAVA. 我需要发布动态文本框并在JAVA的Controller Spring中获取值。 How to get dynamically posted Values in controller? 如何在控制器中动态发布值?
Any Idea? 任何想法?
Are you always sending the same model Object? 您是否总是发送相同模型的对象? I mean, does your form element always has the same name attribute? 我的意思是,您的表单元素是否始终具有相同的name属性?
if yes, you can just create a pojo class with attributes maching your names and use a RequestAttribute
annotation. 如果是的话,您可以只创建一个带有属性的pojo类,该属性可以缓存您的姓名并使用RequestAttribute
批注。
If no, there is no way, you will just have to use the old requestparameter. 如果没有,那就没有办法了,您只需要使用旧的request参数即可。
UPDATE If you dont know what parameters are submitted, loop into all parameters : 更新如果您不知道要提交什么参数,请循环进入所有参数:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.