举例说明:
后台有一个对象 User ,结构如下:
后台有一个对象 User ,结构如下: public class User{ private String username; private List<PhotoDo> photo; ..get ....set..... } public class PhotoDo{ private String id; private String name; ...get...set... }
Controller中接受方法 getUser
@reqeustMapping("/getUser") public void getUser(User user){ ...实现方法... } 前台Form这么写: <form> <input type="text" name="username" aciton=".."> <input type="text" name="photo[0].id"> <input type="text" name="photo[0].name"> <input type="text" name="photo[1].id"> <input type="text" name="photo[1].name"> <input type="text" name="photo[2].id"> <input type="text" name="photo[2].name"> </form>
这里下标可以用var = status-1来解决
第二个例子:
对象Cltc和list实体类
package com.ABC.pojo; import java.util.Date; public class Cltc { private Integer id; private Integer classid;//班级id private Integer teacherid;//教师id private Integer courseid;//课程id private Date time;//排课时间 private Date start;//开始上课时间 private Date end;//结束上课时间 private Classinfo classinfo;//班级 排课状态和 结课状态 入学时间 public Classinfo getClassinfo() { return classinfo; } public void setClassinfo(Classinfo classinfo) { this.classinfo = classinfo; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getClassid() { return classid; } public void setClassid(Integer classid) { this.classid = classid; } public Integer getTeacherid() { return teacherid; } public void setTeacherid(Integer teacherid) { this.teacherid = teacherid; } public Integer getCourseid() { return courseid; } public void setCourseid(Integer courseid) { this.courseid = courseid; } public Date getTime() { return time; } public void setTime(Date time) { this.time = time; } public Date getStart() { return start; } public void setStart(Date start) { this.start = start; } public Date getEnd() { return end; } public void setEnd(Date end) { this.end = end; } @Override public String toString() { return "Cltc [id=" + id + ", classid=" + classid + ", teacherid=" + teacherid + ", courseid=" + courseid + ", time=" + time + ", start=" + start + ", end=" + end + ", classinfo=" + classinfo + "]"; } }
/************************************************/
package com.ABC.vo; import java.util.List; import com.ABC.pojo.Cltc; public class CltcFormVo { private List<Cltc> cltcList; public List<Cltc> getCltcList() { return cltcList; } public void setCltcList(List<Cltc> cltcList) { this.cltcList = cltcList; } }
controller层
@reqeustMapping("paike") public void getCltcFormVo(CltcFormVo cltcFormVo){ List<Cltc> cltcList = cltcFormVo.getCltcList(); ...实现方法... }
jsp页面的信息:
<div class="panel panel-default"> <div class="panel-heading">排课信息</div> <table id="stuTable" class="table table-hover table-striped table-bordered" border="1"> <tr> <th class="text-center" style="50px">顺序</th> <th class="text-center">课程</th> <th class="text-center">老师</th> <th class="text-center" style="200px" >开始时间</th> <th class="text-center" style="200px" >结束时间</th> </tr> <!--页面的接收信息--> <!--注意这里的 [status-1]相当于从0开始往下循环 cltcList[status-1]中的cltcList必须和CltcFormVo中的 private List<Cltc> cltcList; cltcList一样 --> <c:forEach items="${courseList }" var="course" varStatus="status"> <input type="hidden" id="classid" name="cltcList[${status.count-1 }].classid" value="${classinfo.id }"> <input type="hidden" id="time" name="cltcList[${status.count-1 }].time" value="2018-09-09" /> <tr> <td id="count" class="text-center">${status.count}</td> <input type="hidden" id="courseid" name="cltcList[${status.count-1 }].courseid" value="${course.id }"> <td >${course.name }</td> <td> <select class="form-control" id="teacherid" name="cltcList[${status.count-1 }].teacherid"> <option value="${course.teacher.id }">${course.teacher.name }</option> </select> </td> <td><input id="start" name="cltcList[${status.count-1 }].start" class="form-control" type="text" onclick="WdatePicker();"/></td> <td><input id="end" name="cltcList[${status.count-1 }].end" class="form-control" type="text" onclick="WdatePicker();"/></td> </tr> </c:forEach> <tr> <td colspan="5" class="text-center"> <!-- onclick="window.location.href='/paike/cltc/paiKe?id=${cltc.id}'" --> <input id="save" type="button" class="btn btn-success" value="保存排课" /> <input id="cancel" type="button" class="btn btn-danger" value="取消排课" /> </td> </tr> </table> </div>