当前位置:网站首页>通过源码探究@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
边栏推荐
- Leak detection and vacancy filling (V)
- 虚拟环境中使用jupyter notebook
- file_ get_ Two solutions to content accessing SSL errors
- openvswitch 编译安装
- MySQL【ACID+隔离级别+ redo log + undo log】
- 如何通过dba_hist_active_sess_history分析数据库历史性能问题
- Offset et client pour obtenir des informations sur l'emplacement des éléments Dom
- 你应该知道的 JVM 基础知识
- Implementation of leetcode question brushing str ()
- The arithmetic square root of X in leetcode
猜你喜欢
随机推荐
Redis 详解(基础+数据类型+事务+持久化+发布订阅+主从复制+哨兵+缓存穿透、击穿、雪崩)
rdma 编程详解
MySQL 【读写锁+表锁+行锁+MVCC】
mysql密码过期的方法
异常记录-14
DNA reveals surprise ancestry of mysterious Chinese mummies
[Lombok quick start]
volatile 关键字的三大特点【数据可见性、指令禁止重排性、不保证操作原子性】
【MySQL基础篇】启动选项、系统变量、状态变量
ansible模块之include_tasks:为什么加了tags后导入的任务没有执行?
virtio 与vhost_net介绍
JS regular matching first assertion and last assertion
Baidu map coordinates, Google coordinates and Tencent coordinates are mutually transformed
Unix期末考试总结--针对直系
mysql中sum (if)_mysql 中sum (if())
异常记录-22
PHP unlimited classification and tree
【代码解析(1)】Communication-Efficient Learning of Deep Networks from Decentralized Data
【代码解析(3)】Communication-Efficient Learning of Deep Networks from Decentralized Data
并发优化请求









