Skip to content

Commit ae7aa67

Browse files
committed
Add episode 36
1 parent 8b703a2 commit ae7aa67

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# 2019.11.15 「小马哥技术周报」- 第三十六期《阿里开源工程 Spring WebMVC 扩展之内容协商》
2+
3+
4+
5+
6+
7+
### 客户端请求
8+
9+
https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation
10+
11+
```
12+
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
13+
```
14+
15+
16+
17+
### 服务端响应
18+
19+
```
20+
content-type: text/html; charset=utf-8
21+
```
22+
23+
24+
25+
```
26+
content-type: application/xml; charset=utf-8
27+
```
28+
29+
30+
31+
32+
33+
## Spring Web MVC 视图处理
34+
35+
36+
37+
### 视图模板
38+
39+
`@Controller`
40+
41+
HandlerMethod 方法返回的内容视图的地址
42+
43+
### REST 处理
44+
45+
`@RestController` = `@Controller` + `@ResponseBody`
46+
47+
HandlerMethod 方法返回的 Body 内容
48+
49+
`ResponseEntity` = Body + Header
50+
51+
52+
53+
54+
55+
HandlerMethod = public 方法标注 `@RequestMapping`
56+
57+
58+
59+
60+
61+
### 架构特色
62+
63+
Spring Web MVC 允许多套视图处理器(ViewResolver)并存
64+
65+
66+
67+
#### 模板渲染
68+
69+
##### 媒体类型(Accept 请求)
70+
71+
text/html -> Velocity
72+
73+
> text/*
74+
>
75+
> */*
76+
77+
text/json -> themleaf
78+
79+
text/xml -> JSP
80+
81+
##### 请求后缀(URL)
82+
83+
xxx.html -> Velocity
84+
85+
xxx.json -> themleaf
86+
87+
xxx.xml -> JSP
88+
89+
90+
91+
92+
93+
URL : http://acme.com/abc.json?format=application/xml
94+
95+
Accept : text/html
96+
97+
98+
99+
100+

0 commit comments

Comments
 (0)