Preserving model state with Post/Redirect/Get pattern

前端 未结 3 1591
名媛妹妹
名媛妹妹 2021-02-15 16:08

At the moment I am trying to implement the Post/Redirect/Get pattern with Spring MVC 3.1. What is the correct way to preserve and recover the model data + validation errors? I k

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 16:49

    Why don't you show the update form after the binding fails, so the user can try to resubmit the form?

    The standard approach for this seems to be to return the update form view from the POST handler method.

    if (bindingResult.hasErrors()) {
      uiModel.addAttribute("user", user);
      return "user/create";
    }
    

    You can then display errors with the form:errors tag.

提交回复
热议问题