页面提交 string数组和list对象集合举例
ajax表单提交
$.ajax({
cache: true,
type: "POST",
url:ajaxCallUrl,
data:$('#yourformid').serialize(),// 你的formid
async: false,
error: function(request) {
alert("Connection error");
},
success: function(data) {
$("#commonLayout_appcreshi").parent().html(data);
}
});
表单中用 字段对应的是 name 不是id
普通提交表单:直接在form表单中加个id,<form id="formId"></form>,弄个buttom按钮进行提交,加个onclick="js函数",然后在js函数中$("#formId").submit(); 就OK.
=========================
继前面一篇 springMVC 页面中多个对象的数据绑定 ,本文主要介绍如果实现复杂类型对象的数据绑定,比如前文中的父级对象CourseInfo 中增加:String[] times , List<Student> studentList 这两个复杂类型属性,页面中数据如何才能准确绑定到对象上呢?
参考来源:http://www.360doc.com/content/16/1022/15/37520906_600479377.shtml
【类】
public class CourseInfo {
private Course course;
private Teacher teacher;
private String[] times;
private List<Student> studentList;
}
public class Student extends IdEntity {
private String name;
private String email;
private String className;
}
【页面】
1 <form:form id="input-form" modelAttribute="courseInfo" 2 action="${ctx}/demo/course.do?method=save" method="post"> 3 <input type="hidden" name="id" value="${course.id}" /> 4 <fieldset class="prepend-top"> 5 <legend>课程信息</legend> 6 <div id="messageBox" class="error-msg" style="display: none">输入有误,请先更正。</div> 7 <div> 8 <label for="course.name" class="field">课程名称:</label> 9 <input 10 type="text" id="course.name" name="course.name" size="20" 11 value="${courseInfo.course.name}" class="required" /> 12 </div> 13 <div> 14 <label for="course.description" class="field">课程介绍:</label> 15 <input 16 type="text" id="course.description" name="course.description" 17 size="20" value="${courseInfo.course.description}" class="required" /> 18 </div> 19 20 <div> 21 <label for="teacher.name" class="field">老师姓名:</label> 22 <input 23 type="text" id="teacher.name" name="teacher.name" size="20" 24 value="${courseInfo.teacher.name}" class="required" /> 25 </div> 26 <div> 27 <label for="teacher.email" class="field">老师Email:</label> 28 <input 29 type="text" id="teacher.email" name="teacher.email" size="20" 30 value="${courseInfo.teacher.email}" class="required" /> 31 </div> 32 <div> 33 <label for="times" class="field">上课时间:</label> 34 <input type="text" id="times[0]" name="times" size="20" value="周一" class="required" /> 35 <input type="text" id="times[1]" name="times" size="20" value="周三" class="required" /> 36 <input type="text" id="times[2]" name="times" size="20" value="周五" class="required" /> 37 </div> 38 39 <div> 40 <label for="studentList[0].name" class="field">学生1姓名:</label> 41 <input type="text" id="studentList[0].name" name="studentList[0].name" size="20" value="学生1姓名" class="required" /> 42 </div> 43 <div> 44 <label for="studentList[0].email" class="field">学生1Email:</label> 45 <input type="text" id="studentList[0].email" name="studentList[0].email" size="20" value="学生1Email" class="required" /> 46 </div> 47 <div> 48 <label for="studentList[1].name" class="field">学生2姓名:</label> 49 <input type="text" id="studentList[1].name" name="studentList[1].name" size="20" value="学生2姓名" class="required" /> 50 </div> 51 <div> 52 <label for="studentList[1].email" class="field">学生2Email:</label> 53 <input type="text" id="studentList[0].email" name="studentList[1].email" size="20" value="学生2Email" class="required" /> 54 </div> 55 </fieldset>