当前位置:网站首页>通过源码探究@ModelAndView如何实现数据与页面的转发
通过源码探究@ModelAndView如何实现数据与页面的转发
2022-04-23 06:00:00 【0oIronhide】

首先给ModelAndView附上model数据与视图名,在return语句上打断点,url访问该controller,
在返回ModelAndView对象之前,springmvc 会先调用 DispatcherServlet 类中的 doDispatch 方法,

在该方法中有通过 HandlerAdapter 获取controller中 ModelAndView 对象的方法ha.handle():


当debug到该方法时


可以看到此时的mv对象为null,当走完这个ha.handle()方法后在看mv:

model中的数据与view视图名都拿到了,走完ha.handle()方法之后,进入到 DispatcherServlet 类中的第二个方法processDispatchResult()

可以看到在该方法中调用了this.render(mv, request, response);方法,判断mv对象后进入render提交方法中,在该方法中看到调用了view.render()方法,mv.getModelInternal()就是获取model数据;

进入view.render()方法:

其调用了this.renderMergedOutputModel(),进入这个方法:

其调用了两个关键方法,this.exposeModelAsRequestAttributes(model, request);与rd.forward(request, response);,第二个方法很好辨认,rd就是request的 RequestDispatcher 调用 forward 转发页面,那可以猜想 exposeModelAsRequestAttributes() 方法就是把model中的数据赋予 request,进入exposeModelAsRequestAttributes():

在该方法中看到了request.setAttribute(modelName, modelValue);,可以确认该方法就是将model数据赋予request;
以下用画图来说明一下流程:

版权声明
本文为[0oIronhide]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_38599840/article/details/105160928
边栏推荐
- 使用百度智能云人脸检测接口实现照片质量检测
- JS handwriting compatibility event binding
- 【代码解析(2)】Communication-Efficient Learning of Deep Networks from Decentralized Data
- 异常记录-9
- [OSS file upload quick start]
- 【代码解析(1)】Communication-Efficient Learning of Deep Networks from Decentralized Data
- Basic concepts of database: OLTP / OLAP / HTAP, RPO / RTO, MPP
- 数据库基本概念:OLTP/OLAP/HTAP、RPO/RTO、MPP
- Centos8 builds php8 0.3 operating environment
- How to use tiup to deploy a tidb V5 0 cluster
猜你喜欢

TP5 uses redis

使用百度智能云人脸检测接口实现照片质量检测

postMan 传参总结

基於DPDK實現VPC和IDC間互聯互通的高性能網關

Batch modify / batch update the value of a field in the database

压力测试工具 Jmeter

Kids and COVID: why young immune systems are still on top

rdma 编程详解

Decentralized Collaborative Learning Framework for Next POI Recommendation

LeetCode刷题|38外观数组
随机推荐
[no steps in a small step to a thousand miles] Oracle Application derivative ora-01455 error reporting processing
SQL学习|窗口函数
Unix期末考试总结--针对直系
【Shell脚本练习】将新加的磁盘批量添加到指定的VG中
虚拟环境中使用jupyter notebook
How to use DBA_ hist_ active_ sess_ History analysis database history performance problems
MySQL索引【数据结构+索引创建原则】
2021年国产数据库12强介绍
Oracle Performance Analysis Tool: oswatcher
SQL学习|集合运算
PHP background parsing after JQ serialization
How to use tiup to deploy a tidb V5 0 cluster
端口占用1
【ES6快速入门】
Introduction to the top 12 domestic databases in 2021
Kids and COVID: why young immune systems are still on top
SSM项目在阿里云部署
ES入门学习笔记
[ES6 quick start]
postMan 传参总结