在spring控制器中有一个返回类型模型和视图。因为我将一个JSON数组返回给视图。现在我想使用ajax将JSON数组放在Jqgrid或可编辑的数据网格结构中。任何人都可以帮助我或告诉我如何做到这一点。
这是我的控制器: -
@Override
@SuppressWarnings("rawtypes")
protected ModelAndView onSubmit(Object command) throws Exception {
rel_details reldetails = (rel_details) command;
List l=reldetailsdao.save_release_details(reldetails);
JSONObject responseDetailsJson = new JSONObject();
JSONArray jsonArray = new JSONArray();
Iterator itr=l.iterator();
rel_details asd=null;
while(itr.hasNext()){
asd=(rel_details)itr.next();
JSONObject formDetailsJson = new JSONObject();
formDetailsJson.put("rel_id", asd.getRel_id());
formDetailsJson.put("rel_name", asd.getRel_name());
formDetailsJson.put("rel_modified_date", asd.getRel_modified_date());
formDetailsJson.put("rel_desc", asd.getRel_desc());
formDetailsJson.put("rel_env", asd.getRel_env());
formDetailsJson.put("rel_change_req_no", asd.getRel_change_req_no());
formDetailsJson.put("rel_status", asd.getRel_status());
jsonArray.add(formDetailsJson);
}
responseDetailsJson.put("l", jsonArray);
System.out.println(responseDetailsJson);
return new ModelAndView("release","rel",responseDetailsJson);
}
这是jsp: -
<form:form action="release_view.htm" method="POST"
commandName="rel_view_details" target="frame3">
<c:if test="${fn:length(rel) > 0}">
<table align="center" border=1px>
<tr>
<th>Release ID</th>
<th>Release Name</th>
<th>Release Date</th>
<th>Release Description</th>
<th>Release Environment</th>
<th>Change Request No.</th>
<th>Work Status</th>
</tr>
<c:forEach items="${rel}" var="rel" varStatus="status">
<tr>
<td><input type="radio" name="rel_id" id="rel_id"
value="${rel.rel_id}"><a
href="<c:url value="/view_change.htm?rel_id=${rel.rel_id}"/>"
target="frame3"> ${rel.rel_id}</a></td>
<td>${rel.rel_name}</td>
<fmt:formatDate value="${rel.rel_modified_date}" type="date"
pattern="dd-MMM-yyyy" var="rel_modified_date" />
<td>${rel_modified_date}</td>
<td>${rel.rel_desc}</td>
<td>${rel.rel_env}</td>
<td>${rel.rel_change_req_no}</td>
<td>${rel.rel_status}</td>
</tr>
</c:forEach>
</table>
<input type="submit" value="Modify/Delete" />
</c:if>
</form:form>
<div style="color: red;">${rel}</div>
</body>
</html>