SpringMVC框架
標註@Controller,註釋controller層
標註@Service,註釋service層
標註@RequestMapping("/login"),表示訪問鏈接
標註@RequestParam(“name”),表示鏈接參數
標註@Autowired,表示自動注入
最終效果:瀏覽器訪問localhost:8080/login,執行controller中標註@RequestMapping("/login")的方法
HandlerMethod初始化
思考:將標註的訪問鏈接和方法,使用map初始化出來。key存放鏈接,value存放方法名稱。獲取到訪問鏈接後,直接去map中查找對應的執行方法。
HttpServlet方法
HttpServlet有3個主要方法,init、doGet、doPost。init會在項目初始化時運行,doGet和doPost分別在有get和post請求是調用。因此,可以HandlerMethod在init中初始化好,doGet或者doPost時,獲取到訪問鏈接,執行對應的方法
SpringMVC框架圖
經過上述分析,SpringMVC最爲重要的邏輯就是HandlerMethod的初始化和後續的訪問。
碼雲地址:[https://gitee.com/xumiaofeng/springmvc]