【发布时间】:2013-10-02 15:41:06
【问题描述】:
注意:最终我的目标只是将生成的 URL 从“/public/academy/register?param=blah”更改为自定义的 SEO 化 URL,如代码所示。如果我通过尝试从在 POST 映射中返回“成功视图”JSP 更改为使用 post-redirect-get(无论如何这是一个很好的做法)而走错了路,我愿意接受建议。
以下是两种方法:获取注册表单并进行处理的 POST 请求映射,以及成功页面的映射方法。我正在为重定向添加一个 flash 属性,该属性包含 POST 到第一个方法的表单。
表单具有Form -> Schedule -> Course -> Content -> Vendors 的属性层次结构,其中每个都是它自己的类对象,除了Vendors 是SortedSet<Vendor>。当我加载成功页面时,我收到一个 Hibernate 异常,指出无法延迟初始化供应商。为什么它在链条的下游如此之远以至于它停止加载,或者更基本上,为什么它首先失去了这个属性值?当我在返回之前设置断点时,RedirectAttributes 对象以我传递给它的表单填充了供应商。什么给了?
@RequestMapping(value = "/public/academy/register", method = RequestMethod.POST)
public String processSubmit(Site site, Section section, User user,
@ModelAttribute @Valid AcademyRegistrationForm form,
BindingResult result, Model model, RedirectAttributes redirectAttributes) {
validator.validate(form, result);
if (site.isUseStates()
&& StringUtils.isBlank(form.getBooker().getState())) {
result.rejectValue("booker.state",
"gui.page.academy.attendee.state");
}
if (result.hasErrors()) {
LOG.debug("Form has errors: {}", result.getAllErrors());
return "common/academy-registration";
}
// Form is valid when no errors are present. Complete the registration.
AcademyRegistration registration = form.toAcademyRegistration();
academyService.performRegistration(registration, site);
redirectAttributes.addFlashAttribute(form);
String redirectUrl = "redirect:/public/academy/register/"
+ registration.getSchedule().getCourse().getContent().getSeoNavTitle()
+ "-completed";
return redirectUrl;
}
@RequestMapping(value="/public/academy/register/**-completed", method=RequestMethod.GET)
public String displayRegistrationSuccess(@ModelAttribute("academyRegistrationForm") final AcademyRegistrationForm form)
{
SortedSet<Vendor> dummy = form.getSchedule().getCourse().getContent().getVendors();
return "common/academy-registration-success";
}
这是一个例外:
Oct 2, 2013 2:11:31 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.horn.cms.domain.Content.vendors, could not initialize proxy - no Session
【问题讨论】:
-
请发布休眠异常。
-
完成了 Sotirios,感谢您的提醒。
标签: spring hibernate spring-mvc post-redirect-get