Tôi đang mắc kẹt cố gắng để vượt qua BindingResult qua RedirectionAttributes:Đi qua BindingResult qua RedirectionAttributes
Tôi đã tham chiếu Spring - Redirect after POST (even with validation errors), nhưng vẫn còn bị mắc kẹt.
Tôi có một phương thức GET:
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(@ModelAttribute("exampleForm") final ExampleForm exampleForm, final Model model)
{
return "test";
}
và một phương thức POST:
@RequestMapping(value = "/doSomething", method = RequestMethod.POST)
public String doSomething(@Valid @ModelAttribute("exampleForm") final ExampleForm exampleForm, final BindingResult bindingResult, final RedirectAttributes redirectAttributes)
{
if (bindingResult.hasErrors())
{
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.exampleForm", bindingResult);
redirectAttributes.addFlashAttribute("exampleForm", exampleForm);
return "redirect:/test";
}
}
Tuy nhiên, tôi không nhìn thấy lỗi ràng buộc trong mô hình của phương thức GET (sau khi chuyển hướng) khi tôi nhận chúng trong phương thức POST - chúng dường như biến mất.
Đây là đối tượng bindingResult trong phương thức POST: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Dưới đây là sự xâm nhập mô hình trong phương thức GET thấy 0 lỗi: org.springframework.validation.BindingResult.exampleForm=org.springframework.validation.BeanPropertyBindingResult: 0 errors
Bất kỳ trợ giúp sẽ được nhiều đánh giá cao.
Có thể trùng lặp của [Mùa xuân - Chuyển hướng sau POST (ngay cả với lỗi xác thực)] (http://stackoverflow.com/questions/2543797/spring-redirect-after-post-even-with-validation-errors) – Eric