• spring mvc RedirectAttributes


    org.springframework.web.servlet.mvc.support.RedirectAttributes

    org.springframework.web.servlet.mvc.support.RedirectAttributes to specify the exact set of attributes to use in case of a redirect and also to add flash attributes (attributes stored temporarily on the server-side to make them available to the request after the redirect). RedirectAttributes is used instead of the implicit model if the method returns a "redirect:" prefixed view name or RedirectView.

      该类用来存储指定的属性集合,其中包括重定向的一些属性参数和一些临时属性信息(这些属性存储在服务器的临时空间中,为了使它们在重定向后对于request依然可以使用)。当方法中返回一个"redirect:"前缀的视图名或者重定向视图,RedirectAttributes被用来替代隐含的model属性。

    By default all model attributes are considered to be exposed as URI template variables in the redirect URL. Of the remaining attributes those that are primitive types or collections/arrays of primitive types are automatically appended as query parameters.

      默认情况下,所有模型属性都被认为是在重定向的URL中暴露URI模版变量的。剩下的那些原始类型属性,或者原始类型的集合或数组属性,自动追加在后面作为查询参数。

    In annotated controllers however the model may contain additional attributes originally added for rendering purposes (e.g. drop-down field values). To gain precise control over the attributes used in a redirect scenario, an @RequestMapping method can declare an argument of type RedirectAttributes and use it to add attributes for use in RedirectView. If the controller method does redirect, the content of RedirectAttributes is used. Otherwise the content of the default Model is used.

      然而在注解的控制类中,model可能包含最初添加的额外属性以用来提交目的。为了获取精确的控制,通过重定向方案中的属性信息,一个@RequestMapping方法能够声明一个RedirectAttributes类型的参数,并将该属性用在RedirectView中。如果这个控制器重定向了,RedirectAttributes中的内容会被使用。否则使用的是默认model中的内容。

    The RequestMappingHandlerAdapter provides a flag called "ignoreDefaultModelOnRedirect" that can be used to indicate the content of the default Model should never be used if a controller method redirects. Instead the controller method should declare an attribute of type RedirectAttributes or if it doesn’t do so no attributes should be passed on to RedirectView. Both the MVC namespace and the MVC Java config keep this flag set to false in order to maintain backwards compatibility. However, for new applications we recommend setting it to true

      RequestMappingHandlerAdapter提供了一个标识名为”ignoreDefaultModelOnRedirect",能够用来指明,当一个控制器方法重定向时,默认model中哪些内容内容应该永远不被使用。相反的控制器方法应该声明一个RedirectAttribute属性,或者当它不这么做时,应该没有属性被传递给RedirecView。mvc命名空间和mvcjava配置需要声明这个标识为false,目的是保留向后的兼容性。然而对于新的应用我们推荐设置为true。

    The RedirectAttributes interface can also be used to add flash attributes. Unlike other redirect attributes, which end up in the target redirect URL, flash attributes are saved in the HTTP session (and hence do not appear in the URL). The model of the controller serving the target redirect URL automatically receives these flash attributes after which they are removed from the session. See Section 17.6, “Using flash attributes” for an overview of the general support for flash attributes in Spring MVC.

    这个RedirectAttributes接口可以被用来添加临时的属性。和那些在目标重定向URL结束的重定向参数不同,临时属性被记载在session中(今后不会在rul中出现)。控制器的model提供了目标重定向地址自动接收这些零时参数,当他们从session中被移除时。17.6章节讲述springmvc如何支持临时属性信息

  • 相关阅读:
    SQLalchemy 字段类型
    爬虫学习
    Linux了解一下
    django-rest-framework
    vue相关理论知识
    Django认证系统
    Form组件
    JS之AJAX
    Django之中间件
    Django之ORM
  • 原文地址:https://www.cnblogs.com/brolanda/p/4514844.html
Copyright © 2020-2023  润新知