我不是在春天控制器获取表单数据提交以下表单后,后是我的代码表单数据未使用Spring控制器注释获得新的对象绑定提交
@RequestMapping(value = "category/addCategory.htm" , method = RequestMethod.GET)
public String add(Model model) {
if (log.isDebugEnabled()){
log.debug("Invoking listCategory");
}
model.addAttribute("categoryView", new CategoryView());
return "editCategory";
}
@RequestMapping(value = "category/saveCategory.htm", method = RequestMethod.POST)
public String saveCategory(CategoryView categoryView, Model model, BindingResult result) {
Category category = prepareCategoryFromView(categoryView);
categoryService.save(category);
categoryView.setCategoryId(category.getCategoryId());
model.addAttribute("categoryView",categoryView);
return "editCategory";
}
prepareCategoryFromView是被设定的实际值的方法在类别它的休眠实体,以下类别查看
public class CategoryView {
private long categoryId;
private String image = "";
private int parentId;
private boolean top;
private int column = 1;
private int sortOrder = 1;
private boolean status;
private String description;
private String name;
.
.
other variable and setter and getters
}
和形式是
<sf:form method="post" enctype="multipart/form-data" id="form-category" cssClass="form-horizontal" modelAttribute="categoryView">
<sf:label path="name" cssClass="col-sm-2 control-label">Category Name</sf:label>
<sf:input path="name" id="name" name="name" cssClass="form-control" placeholder="Category Name" />
<sf:hidden path="categoryId" id="categoryId" name="categoryId" />
<sf:hidden path="languageId" id="languageId" name="languageId" />
<sf:label path="description" cssClass="col-sm-2 control-label">Category Name</sf:label>
<sf:textarea path="description" cssClass="form-control" placeholder="Description" id="description"/>
.
.
.
</sf:form>
在上述表单中的每个我得到的名称和说明时间为空(我认为这是创建一个新的视图对象,而不在形式给出的值)
请让我知道,在这里我错了
在你的saveCategory方法重新排序参数,在categoryView后立即放置BindingResult,离开模型最后,或摆脱,看看会发生什么 – grid 2014-11-05 15:22:25
按照你的说法试过,但没有解决。同样的问题 – user3682520 2014-11-05 16:47:10
如果在输入帖子处理程序后立即添加断点,是否填充了categoryView? – grid 2014-11-05 16:50:41