zoukankan      html  css  js  c++  java
  • SpringMVC中重定向参数的使用以及原理解析 RedirectAttributes

    SpringMVC中重定向参数的使用以及原理解析
    
    OUTPUT_FLASH_MAP_ATTRIBUTE::org.springframework.web.servlet.DispatcherServlet#OUTPUT_FLASH_MAP_ATTRIBUTE
    INPUT_FLASH_MAP_ATTRIBUTE::org.springframework.web.servlet.DispatcherServlet#INPUT_FLASH_MAP_ATTRIBUTE
    
    
    
    springMVC通过org.springframework.web.servlet.support.RequestContextUtils#getOutputFlashMap方法获取OUTPUT_FLASH_MAP_ATTRIBUTE标识下的map,并向其中放入数据。
    参考(spring-webmvc-5.2.0.RELEASE.jar)org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#getModelAndView方法下的(1010行)
    
    
    然后通过org.springframework.web.servlet.support.RequestContextUtils#saveOutputFlashMap方法进行设置
    步骤如下:首先调用org.springframework.web.servlet.support.RequestContextUtils#getOutputFlashMap方法拿到之前放入的数据,
    然后通过(281行)manager.saveOutputFlashMap(flashMap, request, response);
    放入缓存中。
    
    
    OUTPUT_FLASH_MAP_ATTRIBUTE和INPUT_FLASH_MAP_ATTRIBUTE仅仅是检索和保存的标识,
    实际数据存储在session数据的该org.springframework.web.servlet.support.SessionFlashMapManager#FLASH_MAPS_SESSION_ATTRIBUTE标识下
    参考类:org.springframework.web.servlet.support.SessionFlashMapManager
    
    
    使用方法:
    
    set数据
    使用如下方法存入要在重定向之后使用的数据:
    使用RedirectAttributes参数类型
    	@RequestMapping(value="xxxx", method=RequestMethod.POST)
    	public String addCustomer(final RedirectAttributes redirectAttributes) {
    		redirectAttributes.addFlashAttribute("customer", customer);
    		redirectAttributes.addFlashAttribute("message","Added successfully.");
    		return "redirect:xxxxxx.html";	
    	}
    实现原理在:org.springframework.web.servlet.mvc.method.annotation.RedirectAttributesMethodArgumentResolver 使用参数解析处理方法
    
    
    
    get数据
    重定向之后,会将上述数据直接放入Model、Map、ModelAndView等数据模型中,可直接使用。
    源码位置:(spring-webmvc-5.2.0.RELEASE.jar)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#invokeHandlerMethod下的
    (864行)mavContainer.addAllAttributes(RequestContextUtils.getInputFlashMap(request));
    

      

  • 相关阅读:
    Python性能分析指南
    centos加入启动服务
    北京户口
    北京户口
    【汽车进口税】 关于汽车进口税计算你知道多少-汽车保险资讯-阳光车险官方网站
    在北京公司要多长时间才可以申请摇车牌号
    Kivy: Crossplatform Framework for NUI
    说说设计模式~大话目录(Design Pattern)
    说说设计模式~策略模式(Strategy)
    说说设计模式~装饰器模式(Decorator)
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/12144258.html
Copyright © 2011-2022 走看看