gpt4 book ai didi

java - Spring MVC中无法通过ajax调用绑定(bind)ModelMap

转载 作者:行者123 更新时间:2023-12-01 12:07:01 25 4
gpt4 key购买 nike

我的 JSP 页面:

<form action="manageparentexamforchildren.htm" class="form-horizontal form-bordered" >
<div class="form-body">
<div class="form-group">
<label class="control-label col-md-1"><spring:message code="label.parent.children"/></label>
<div class="col-md-3">
<select name="parent.children" class="form-control" id="children" required="true" >
<option value="">-<spring:message code="label.select"/>-</option>
<c:forEach items="${studentsOfThisParent}" var="student">
<option value="${student.id}">${student.firstName} ${student.lastName}</option>
</c:forEach>
</select>
</div>
</div>

</div>
<div class="form-actions fluid">
<div class="row">
<div class="col-md-12">
<div class="col-md-offset-3 col-md-9">
<button type="submit" class="btn blue"><i class="icon-ok"></i><spring:message code='button.search'/></button>
<button type="button" onclick="javascript:history.go(-1);" class="btn red default"><spring:message code='button.cancel'/></button>
</div>
</div>
</div>
</div>
</form>


<c:forEach items="${modelList}" var="examination">
<tr>
<td><b><spring:message code="label.examination.schoolexam"/></b>:<c:out value="${examination.schoolExam.name}" /></td>
</tr>

<table border="1" width="1000" height="200" class="table table-bordered table-hover">
<thead> <tr><th class="active"><spring:message code="label.examination.subjects"/></th><th class="active"><spring:message code="label.exam.Date"/></th><th class="active"><spring:message code="label.exam.maxmarks"/></th></tr></thead>
<tbody>
<c:forEach items="${examination.examinationSubjects}" var="examinationSubject" varStatus="status">
<tr>
<td class="success"><c:out value="${examinationSubject.subjects.name}" /></td>
<td class="success" ><c:out value="${examinationSubject.date}" /></td>
<td class="success"><c:out value="${examinationSubject.maxMarks}" /></td>

</tr>
</c:forEach>
</tbody>
</table>

</c:forEach>

我的 Controller :

@RequestMapping(value="/manageparentexam.htm", method=RequestMethod.GET)
public String manageparentexam(ModelMap modelMap,HttpServletRequest request )
{

Parent parent = parentService.getParentById(getLoggedInUser().getId());
List <Student> studentsOfThisParent=parentService.getStudentsOfThisParent(getLoggedInUser().getId());
Student student=null;

student=parent.getStudentAdmission().get(0).getStudent();
modelMap.addAttribute("modelList",student.getStudentAdmission().getClasses().getExamination());


setupCreate(modelMap, request);
return "tileDefinition.manageparentexam-"+getNameSpace();
}



@RequestMapping(value="/manageparentexamforchildren.htm", method=RequestMethod.GET)
public void manageparentexamforchildren(ModelMap modelMap,HttpServletRequest request )
{
Long studentId=Long.valueOf(request.getParameter("parent.children"));
modelMap.addAttribute("modelList",studentService.getById(studentId).getStudentAdmission().getClasses().getExamination());
setupCreate(modelMap, request);
}

这里我的要求是,每当我在选择框中选择一个值,那么表应该通过ajax更新,这里我无法通过ajax调用绑定(bind)模型列表。 。 。

最佳答案

我要做的就是将表分离到另一个jsp中。 yourTable.jsp 像这样

        <table border="1" width="1000" height="200" class="table table-bordered table-hover"> 
<thead> <tr><th class="active"><spring:message code="label.examination.subjects"/></th><th class="active"><spring:message code="label.exam.Date"/></th><th class="active"><spring:message code="label.exam.maxmarks"/></th></tr></thead>
<tbody>
<c:forEach items="${examination.examinationSubjects}" var="examinationSubject" varStatus="status">
<tr>
<td class="success"><c:out value="${examinationSubject.subjects.name}" /></td>
<td class="success" ><c:out value="${examinationSubject.date}" /></td>
<td class="success"><c:out value="${examinationSubject.maxMarks}" /></td>

</tr>
</c:forEach>
</tbody>
</table>

然后将此jsp包含在div内的主mapge中

    <div id="yourTable"> 
<c:jsp include="yourTable.jsp/>
</div>

然后在您的选择中,您必须添加一个监听器,当某些内容发生更改时,您需要进行 JQuery 加载以重新加载表格,再次从 Controller 渲染表格,并包含您想要的所有更改

              $('#yourTable').load("url of your controller where you will render yourTable.jsp");

在 Controller 中,您将呈现 yourTable.jsp 并在 ModelAndView 对象中添加 examSubject

关于java - Spring MVC中无法通过ajax调用绑定(bind)ModelMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27521333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com