【发布时间】:2013-02-12 10:54:13
【问题描述】:
我有这门课:
PreApprovalRequest 类有一个属性headings,它会自动填充到控制器中(参见页面下方的控制器代码)。
public class PreApprovalRequest {
private Long id;
private String Description;
private Collection<Headings> headings; //this property!
}
还有控制器:
@Controller
@SessionAttributes({"preApprovalRequest", "productRecommendations"})
public class RequestController {
@RequestMapping(value = "/submit", method = RequestMethod.POST)
public String submitResults(@ModelAttribute(value = "preApprovalRequest") @Valid PreApprovalRequest preApprovalRequest, BindingResult errors) {
//HERE: It looks like if I have some headings in the preApprovalRequest object already, the call of this method will not delete those, but will append to the existing list.
//save object in DB.
return "dashboard";
}
}
知道如何让 Spring 替换集合对象而不是添加到它吗?
【问题讨论】:
-
这是 SessionAttributes 持有相同
preApprovalRequest变量的预期行为。如果您不希望从您提交的内容中创建新的headings,只需将其从SessionAttributes中删除 -
我每次都想要一个新的标题。这就是问题所在,我不明白。 Spring 似乎只是添加到标题列表中,而不是删除旧的并只保留新的。我不知道为什么有人甚至想要那个,不明白他们为什么在 Spring 中这样实现它?!
标签: java spring session spring-mvc