当前位置:网站首页>通过源码探究@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
边栏推荐
- Installing redis using a small leather panel in the window environment
- rdma 介绍
- JQ序列化后PHP后台解析
- DDOS攻击/防御介绍
- Oracle Performance Analysis Tool: oswatcher
- leetcode刷题之x的算术平方根
- 时间格式不对,运行sql文件报错
- ansible模块之include_tasks:为什么加了tags后导入的任务没有执行?
- Get DOM element location information by offset and client
- A website that directly downloads PNG icons without logging in
猜你喜欢
随机推荐
Solution to page cache problem (use with caution)
SQL学习|窗口函数
【OSS文件上传快速入门】
The time format is incorrect, and an error is reported when running the SQL file
tc ebpf 实践
ubuntu下搭建mysql环境 & 初识SQL
Get DOM element location information by offset and client
[no steps in a small step to a thousand miles] Oracle Application derivative ora-01455 error reporting processing
redis 常见问题
How to use DBA_ hist_ active_ sess_ History analysis database history performance problems
Kids and COVID: why young immune systems are still on top
Leak detection and vacancy filling (IV)
mysql密码过期的方法
[OSS file upload quick start]
【代码解析(6)】Communication-Efficient Learning of Deep Networks from Decentralized Data
SQL学习|基础查询与排列
LeetCode刷题|368最大整除子集(动态规划)
【代码解析(2)】Communication-Efficient Learning of Deep Networks from Decentralized Data
TypeScript(上)
SQL学习|集合运算