我有一个包含一些数据字段的表单,我必须传递一些相应的对象,以便在 Spring 控制器中一起更新。由于 Spring 在“字段 [nestedObject] 上的对象 [parentObject] 中的字段错误”问题上引发了错误,我没有做到这一点。
因为我想象我没有正确处理这些对象。如何操作这些对象以便 Spring MVC 正确识别和管理它?
代码如下:
对应的JSP页面:
<form id="fmActivity"
method="post"
accept-charset="iso-8859-1,utf-8"
novalidate>
<div class="fitem">
<label>Description</label>
<textarea id="description" name="description" class="easyui-validatebox" required cols="40" rows="5">
</textarea>
</div>
<div class="fitem">
<label>Comments</label>
<textarea id="comments" name="comments" class="easyui-validatebox" cols="40" rows="5">
</textarea>
</div>
<!-- HERE ARE THE PROBLEMS: PROJECT, EXECUTOR AND DATETIME FIELDS ARE NOT PROCESSED BY SPRING
<div class="fitem">
<label>Project (it would be hidden)</label>
<input id="project" type="hidden" name="project" class="easyui-validatebox" required value="${project}">
</div>
<div class="fitem">
<label>Executor (it would be hidden)</label>
<input id="executor" type="hidden" name="executor" class="easyui-validatebox" required value="${executor}">
</div>
<div class="fitem">
<label>Date/Time</label>
<input id="dateTime" class="easyui-datetimebox" required name="dateTime" style="width:150px">
</div>
-->
<div class="fitem">
<label>Tag</label>
<input name="tag" class="easyui-validatebox" required>
</div>
<input id="button1" name="button1" type="submit" value="submit">
</form>
处理按钮单击的 JQuery 代码:
$('input#button1').click( function() {
$.ajax({
url: 'ActivityUpdate',
type: 'post',
dataType: 'json',
data: $('form#fmActivity').serialize(),
success: function(data) {
alert(data);
},
error: function(errobj, str, errt){
alert(str + " " + errt);
}
});
});
和 MVC 控制器:
@RequestMapping(value = "/ActivityUpdate")
public String update(Activity activity, HttpSession httpSession) {
Session sess = (Session) httpSession.getAttribute("hibSess");
ActivityDAO actDao = new ActivityDAO(sess);
actDao.persist(activity);
return "forward:ActivityList";
}
当我尝试在没有对象 PROJECT、EXECUTOR 和 DateTime 的情况下进行处理时,它可以工作。你能帮助我吗?谢谢!