SpringBoot方法传参
代码如下,当浏览器发送/hello请求,调用hello(Model m)方法时,SpringBoot如何知道传入什么类型的参数?毕竟参数类型是开发者定义的,类型千变万化。知道类型后,SpringBoot又是以一个怎么的原理传入参数的?求解答。
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(Model m) {
m.addAttribute("now", DateFormat.getDateTimeInstance().format(new Date()));
return "hello";
}
}
回答
StandardWrapperValve 类下 有一个 invoke,
invoke里面调用 ApplicationFilterChain#doFilter,
还涉及到 FrameworkServlet、Request、DispatcherServlet 等类和对象,
参数解析的奥秘,等你来探索
暂且已经debug 到这里了,后续请关注我的 还没发布的博文,
方法:打开debug级别的日志(命令行参数 --debug),开始 调试(设置断点 开始 debug,会吧?)