{"id":5908,"date":"2022-05-12T15:02:19","date_gmt":"2022-05-12T07:02:19","guid":{"rendered":"http:\/\/123.57.164.21\/?p=5908"},"modified":"2022-05-12T15:02:19","modified_gmt":"2022-05-12T07:02:19","slug":"springboot-%e6%8b%a6%e6%88%aa%e5%99%a8%e7%9a%84%e6%b3%a8%e5%86%8c%e5%92%8c%e4%bd%bf%e7%94%a8%ef%bc%88%e9%99%84%e6%a0%b7%e4%be%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=5908","title":{"rendered":"SpringBoot &#8211; \u62e6\u622a\u5668\u7684\u6ce8\u518c\u548c\u4f7f\u7528\uff08\u9644\u6837\u4f8b\uff09"},"content":{"rendered":"\n<p><strong>Spring MVC <\/strong>\u4e2d\u63d0\u4f9b\u4e86 <strong>AOP<\/strong> \u98ce\u683c\u7684\u62e6\u622a\u5668\uff0c\u62e5\u6709\u66f4\u52a0\u7cbe\u7ec6\u7684\u62e6\u622a\u5904\u7406\u80fd\u529b\u3002<strong>Spring Boot <\/strong>\u4e2d\u62e6\u622a\u5668\u7684\u6ce8\u518c\u4e0e\u4f7f\u7528\u66f4\u52a0\u65b9\u4fbf\uff0c\u4e0b\u9762\u901a\u8fc7\u6837\u4f8b\u8fdb\u884c\u6f14\u793a\u3002<\/p>\n\n\n\n<p><br><strong>1\uff0c\u521b\u5efa\u62e6\u622a\u5668<\/strong><\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u5b9e\u73b0\u00a0<strong>HandlerInterceptor<\/strong> \u63a5\u53e3\u81ea\u5b9a\u4e49\u4e00\u4e2a\u62e6\u622a\u5668\u00a0<strong>MyInterceptor1<\/strong>\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-1024x303.png\" alt=\"\" class=\"wp-image-5909\" width=\"706\" height=\"208\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-1024x303.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-300x89.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-768x227.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-830x245.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-230x68.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-350x103.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104-480x142.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-104.png 1516w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import org.springframework.web.servlet.HandlerInterceptor;\nimport org.springframework.web.servlet.ModelAndView;\n \nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n \npublic class MyInterceptor1 implements HandlerInterceptor {\n \n    @Override\n    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,\n                             Object handler) throws Exception {\n        System.out.println(\"MyInterceptor1>>>preHandle\");\n        return true;\n    }\n \n    @Override\n    public void postHandle(HttpServletRequest request, HttpServletResponse response,\n                           Object handler, ModelAndView modelAndView) throws Exception {\n        System.out.println(\"MyInterceptor1>>>postHandle\");\n    }\n \n    @Override\n    public void afterCompletion(HttpServletRequest request, HttpServletResponse response,\n                                Object handler, Exception ex) throws Exception {\n        System.out.println(\"MyInterceptor1>>>afterCompletion\");\n    }\n}<\/pre>\n\n\n\n<p><strong>2\uff0c\u914d\u7f6e\u62e6\u622a\u5668<\/strong><\/p>\n\n\n\n<p>\u63a5\u7740\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u914d\u7f6e\u7c7b\u6765\u914d\u7f6e\u62e6\u622a\u5668\u3002\u81ea\u5b9a\u4e49\u7c7b\u53ea\u9700\u5b9e\u73b0\u00a0<strong>WebMvcConfigurer<\/strong> \u63a5\u53e3\uff0c\u5b9e\u73b0\u63a5\u53e3\u4e2d\u7684\u00a0<strong>addInterceptors<\/strong> \u65b9\u6cd5\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@Configuration\npublic class WebMvcConfig implements WebMvcConfigurer {\n    @Override\n    public void addInterceptors(InterceptorRegistry registry) {\n    registry.addInterceptor(new MyInterceptor1())\n            .addPathPatterns(\"\/**\") \/\/ \u914d\u7f6e\u62e6\u622a\u8def\u5f84\uff08\u6240\u6709\u8def\u5f84\u90fd\u62e6\u622a\uff09\n            .excludePathPatterns(\"\/hello2\"); \/\/ \u914d\u7f6e\u6392\u9664\u7684\u8def\u5f84\n    }\n}<\/pre>\n\n\n\n<p><strong>3\uff0c\u8fd0\u884c\u6d4b\u8bd5<\/strong><\/p>\n\n\n\n<p>\uff081\uff09\u9996\u5148\u6211\u4eec\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u63a5\u53e3<strong> \/hello1<\/strong>\uff0c\u53ef\u4ee5\u770b\u5230\u63a7\u5236\u53f0\u8f93\u51fa\u4fe1\u606f\u5982\u4e0b\uff0c\u8bf4\u660e\u62e6\u622a\u5668\u6210\u529f\u542f\u7528\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105.png\" alt=\"\" class=\"wp-image-5910\" width=\"536\" height=\"268\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105.png 828w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105-300x150.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105-768x384.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105-230x115.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105-350x175.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-105-480x240.png 480w\" sizes=\"(max-width: 536px) 100vw, 536px\" \/><\/figure><\/div>\n\n\n\n<p>\uff082\uff09\u63a5\u7740\u8bbf\u95ee\u63a5\u53e3<strong> \/hello2<\/strong>\uff0c\u7531\u4e8e\u8be5\u8def\u5f84\u88ab\u6392\u9664\u518d\u5916\uff0c\u56e0\u6b64\u5c31\u6ca1\u6709\u88ab\u62e6\u622a\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106.png\" alt=\"\" class=\"wp-image-5911\" width=\"550\" height=\"305\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106.png 808w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106-300x166.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106-768x426.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106-230x128.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106-350x194.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/05\/\u56fe\u7247-106-480x266.png 480w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring MVC \u4e2d\u63d0\u4f9b\u4e86 AOP \u98ce\u683c\u7684\u62e6\u622a\u5668\uff0c\u62e5\u6709\u66f4\u52a0\u7cbe\u7ec6\u7684\u62e6\u622a\u5904\u7406\u80fd\u529b\u3002Spring Boot \u4e2d\u62e6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/5908"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5908"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/5908\/revisions"}],"predecessor-version":[{"id":5912,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/5908\/revisions\/5912"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}