动手撸一个 mvc 框架6
2020-04-29 本文已影响0人
想54256
title: 动手撸一个 mvc 框架6
date: 2020/04/28 14:21
本节内容
上节我们初步打通了一个请求的流程,已经可以返回数据给前端了,当然我们是直接返回的 json
然而我们发现并没有用到 ModelAndView ,为了更加清楚 ModelAndView 的流程,我们也写一下
Spring 4.0
注:模拟的代码如下:
/*
注入 Model 的那个解析器我就不带大家看了(我自己也没看)
我猜测是从 mavContainer.getModel() 中获取了一个 Model
*/
@RequestMapping("/user/all/{id}")
public String findAll(@PathVariable String id, Model model) {
System.out.println("调用方法");
model.addAttribute("id", id);
return "/WEB-INF/user.jsp";
}
![](https://img.haomeiwen.com/i13787512/04fa03807232c063.jpg)
回到上节的 tag2
![](https://img.haomeiwen.com/i13787512/3b71c26a595a4331.jpg)
点进去把
![](https://img.haomeiwen.com/i13787512/2b2253a61116d18b.jpg)
回到 tag3
![](https://img.haomeiwen.com/i13787512/d4f434d0798c882f.jpg)
![](https://img.haomeiwen.com/i13787512/82a07df503ddec3d.jpg)
回到 DispatcherServlet
![](https://img.haomeiwen.com/i13787512/d39aeb94408ae219.jpg)
![](https://img.haomeiwen.com/i13787512/77979db7f7c6c9ab.jpg)
![](https://img.haomeiwen.com/i13787512/2654741a3217e7d6.jpg)
tag1
视图解析器
![](https://img.haomeiwen.com/i13787512/bd488148d3da67f4.jpg)
![](https://img.haomeiwen.com/i13787512/1120959c3dc486aa.jpg)
![](https://img.haomeiwen.com/i13787512/71b0b3a493888d73.jpg)
![](https://img.haomeiwen.com/i13787512/e95d30a48636aa1f.jpg)
![](https://img.haomeiwen.com/i13787512/1e6d3c1c34cfade2.jpg)
![](https://img.haomeiwen.com/i13787512/44bc5947bbc44f62.jpg)
tag2
![](https://img.haomeiwen.com/i13787512/526fb8437dd90a6e.jpg)
视图解析器的初始化
![](https://img.haomeiwen.com/i13787512/8ef07860dcc79bfe.jpg)