Skip to content

Commit 0a5cadf

Browse files
committed
docs: update
1 parent 9127b46 commit 0a5cadf

File tree

6 files changed

+117
-112
lines changed

6 files changed

+117
-112
lines changed

web/bun.lock

Lines changed: 73 additions & 97 deletions
Large diffs are not rendered by default.
273 KB
Loading
275 KB
Loading
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
---
22
title: WebMVC Controller
3+
description: 控制器,创建独特的 entrypoint 访问路径
34
---
45

5-
WIP
6+
## HandlerMapping
7+
8+
[前面](/docs/springweb#spring-webmvc) 我们有说 WebMVC Controller 控制器实际上就是 Handler,并且由 HandlerMapping 管理着。我们在 getHandler 打断点看一下我们常用的 Spring Boot2 中所拥有的 HandlerMapping 有哪些。
9+
10+
![spring-handler-mappings](../images/spring-handler-mappings.png)
11+
12+
1. **org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping**:为使用 @Controller@RequestMapping 类和方法创建 HandlerMethod。
13+
2. **org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping**:将 beanName 以 `/` 开头的 bean 注册为 Handler。
14+
3. **org.springframework.web.servlet.function.support.RouterFunctionMapping**:收集 RouterFunction bean 组合成为 Handler。
15+
4. **org.springframework.web.servlet.handler.SimpleUrlHandlerMapping**:传入 url 与 handler 映射的 map 组成 HandlerMapping。
16+
5. **org.springframework.boot.autoconfigure.web.servlet.WelcomePageHandlerMapping**:访问 / 转发到 index.html,因此 /index.html 为欢迎页面。
17+
18+
优先级从高往低,从前往后只要获取到能处理当前 request 的 Handler 即返回,所以如果在后面的 HandlerMapping 定义需要确保不能与前面 HandlerMapping 重复。
19+
20+
HandlerMapping 里面决定了我们 Handler 应该如何注册进去的核心逻辑,但是 Handler 该如何编写,由 HandlerAdapter 说了算。
21+
22+
## HandlerAdapter
23+
24+
同样以最常见的 Spring Boot2 为例,在 getHandlerAdapter 打断点,看一下当前支持哪些 HandlerAdapter。
25+
26+
![spring-handler-adapter](../images/spring-handler-adapter.png)
27+
28+
1. **org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter**:需要 handler 为 org.springframework.web.method.HandlerMethod 实例。
29+
2. **org.springframework.web.servlet.function.support.HandlerFunctionAdapter**:需要 handler 继承 org.springframework.web.servlet.function.HandlerFunction。
30+
3. **org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter**:需要 handler 继承 org.springframework.web.HttpRequestHandler。
31+
4. **org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter**:需要 handler 继承 org.springframework.web.servlet.mvc.Controller。
32+

web/content/docs/springweb/index.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,17 @@ protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Ex
154154
}
155155
```
156156

157-
所谓 MVC 中的 C 控制器在 Spring WebMVC 实际上是 Handler,并且由 HandlerMapping 管理,因此我们最常注入的就是 Controller 内存马和 Interceptor 内存马。参考 [SpringWeb 内存马变型 - 银针安全](https://mp.weixin.qq.com/s/aWTcq3690F3CmGGo4A-a0w) 也可以实现其他内存马。
157+
所谓 MVC 中的 C 控制器在 Spring WebMVC 实际上是 Handler,并且由 HandlerMapping 管理。但是最终调用 Handler 哪个方法是由 HandelrAdapter 来决定的。
158+
159+
我们最常注入的就是 Controller 内存马和 Interceptor 内存马。参考 [SpringWeb 内存马变型 - 银针安全](https://mp.weixin.qq.com/s/aWTcq3690F3CmGGo4A-a0w) 也可以实现其他内存马。
158160

159161
<Cards>
160162
<Card
161-
href="/docs/spring/controller"
163+
href="/docs/springweb/controller"
162164
title="Controller 内存马"
163165
>控制器,创建独特的 entrypoint 访问路径</Card>
164166
<Card
165-
href="/docs/spring/interceptor"
167+
href="/docs/springweb/interceptor"
166168
title="Interceptor 内存马"
167169
>拦截器,命中 webshell 逻辑中断请求</Card>
168170
</Cards>
@@ -202,19 +204,19 @@ WebFlux 中同样可以使用 `@Controller` 和 `@RequestMapping`,因此也有
202204

203205
<Cards>
204206
<Card
205-
href="/docs/spring/webfilter"
207+
href="/docs/springweb/webfilter"
206208
title="WebFilter 内存马"
207209
>过滤器,总是需要一种方式对所有进入的请求进行处理</Card>
208210
<Card
209-
href="/docs/spring/handler-method"
211+
href="/docs/springweb/handler-method"
210212
title="HandlerMethod 内存马"
211213
>@RequestMapping,WebMVC 式创建路由的方式</Card>
212214
<Card
213-
href="/docs/spring/handler-function"
215+
href="/docs/springweb/handler-function"
214216
title="HandlerFunction 内存马"
215217
>RouterFunction,函数式路由声明方式</Card>
216218
<Card
217-
href="/docs/spring/netty-handler"
219+
href="/docs/springweb/netty-handler"
218220
title="Netty Handler 内存马"
219221
>Netty Handler API 允许处理 request 和 response</Card>
220222
</Cards>

web/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
},
1414
"dependencies": {
1515
"@hookform/resolvers": "^5.2.2",
16-
"@orama/orama": "^3.1.16",
17-
"@orama/stopwords": "^3.1.16",
18-
"@orama/tokenizers": "^3.1.16",
16+
"@orama/orama": "^3.1.17",
17+
"@orama/stopwords": "^3.1.17",
18+
"@orama/tokenizers": "^3.1.17",
1919
"@react-router/node": "^7.10.1",
2020
"@tanstack/react-query": "^5.90.12",
2121
"class-variance-authority": "^0.7.1",
2222
"clsx": "^2.1.1",
2323
"framer-motion": "^12.23.26",
2424
"fumadocs-core": "^16.2.5",
2525
"fumadocs-mdx": "14.1.0",
26-
"fumadocs-ui": "16.2.4",
27-
"i18next": "^25.7.2",
26+
"fumadocs-ui": "16.2.5",
27+
"i18next": "^25.7.3",
2828
"isbot": "^5.1.32",
2929
"lucide-react": "^0.561.0",
3030
"motion": "^12.23.26",
@@ -56,8 +56,8 @@
5656
"serve": "^14.2.5",
5757
"tailwindcss": "^4.1.18",
5858
"typescript": "^5.9.3",
59-
"vite": "^7.2.7",
59+
"vite": "^7.3.0",
6060
"vite-plugin-devtools-json": "^1.0.0",
61-
"vite-tsconfig-paths": "^5.1.4"
61+
"vite-tsconfig-paths": "^6.0.1"
6262
}
6363
}

0 commit comments

Comments
 (0)