{"id":14591,"date":"2024-05-12T14:45:39","date_gmt":"2024-05-12T06:45:39","guid":{"rendered":"https:\/\/92it.top\/?p=14591"},"modified":"2024-05-12T14:47:48","modified_gmt":"2024-05-12T06:47:48","slug":"%e6%9d%82%e8%b0%88%ef%bc%9aspringmvc%e4%b8%adcontroller%e4%b8%ba%e4%bb%80%e4%b9%88%e8%83%bd%e5%a4%9f%e5%a4%84%e7%90%86%e5%b9%b6%e5%8f%91%e8%ae%bf%e9%97%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=14591","title":{"rendered":"\u6742\u8c08\uff1aSpringMVC\u4e2dController\u4e3a\u4ec0\u4e48\u80fd\u591f\u5904\u7406\u5e76\u53d1\u8bbf\u95ee\uff1f"},"content":{"rendered":"\n<p><strong>\u95ee\u9898<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>SpringMVC\u4e2d\u7528\u6765\u5904\u7406http\u8bf7\u6c42\u7684Controller\u662f\u57fa\u4e8eServlet\u5b9e\u73b0\u7684\uff0cSpring\u4e2d\u7edd\u5927\u591a\u6570\u7684\u7c7b\u90fd\u662f<strong>\u5355\u4f8b<\/strong>\u7684\uff0cServlet\u4e5f\u662f\u8fd9\u6837\u3002<\/p>\n\n\n\n<p>Controller\u3001Service\u3001DAO\u90fd\u662f<strong>\u9ed8\u8ba4\u5355\u4f8b\u6a21\u5f0f<\/strong><\/p>\n\n\n\n<p>\u65e2\u7136Controller\u662f\u5355\u4f8b\u6a21\u5f0f\uff0c\u90a3\u4e48\u5b83\u662f\u600e\u4e48\u80fd\u591f\u5728\u540c\u65f6\u5904\u7406\u5f88\u591a\u4e2a\u8bf7\u6c42\u7684\u5462\uff1f<\/p>\n\n\n\n<p>\u60f3\u8981\u641e\u660e\u767d\u8fd9\u70b9\uff0c\u9996\u5148\u9762\u4e34\u7684\u4e00\u4e2a\u95ee\u9898\u662f\uff1a\u8ba1\u7b97\u673a\u662f\u5982\u4f55\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\u7684\u5462\uff1f<\/p>\n\n\n\n<p>\u8ba1\u7b97\u673a\u5927\u90e8\u5206\u7684\u4efb\u52a1\u90fd\u662f\u7531CPU\u6765\u5b8c\u6210\u7684\uff0cController\u867d\u7136\u53eb\u505a\u63a7\u5236\u5668\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u6267\u884c\u5904\u7406\u4efb\u52a1\u7684\u89d2\u8272\u662fCPU\u3002\u63a7\u5236\u5668\u53ea\u662f\u63d0\u4f9b\u4e86CPU\u5904\u7406\u8bf7\u6c42\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u5b9e\u9645\u4e0a\u662fCPU\u6839\u636eController\u4e2d\u7684\u4ee3\u7801\u6765\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u662f\u8c01\u6765\u63a7\u5236CPU\u6765\u8fdb\u884c\u4efb\u52a1\u5462\uff1f\u5f53\u7136\u662f\u8fdb\u7a0b\u4e86\uff0c\u5728\u6211\u4eec\u9762\u5bf9\u7684\u8ba1\u7b97\u673a\u4e2d\uff0c\u8fdb\u7a0b\u662f\u8fd0\u884c\u7684\u57fa\u672c\u5355\u5143\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u8ba1\u7b97\u673a\u662f\u5982\u4f55\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\u7684\u5462\uff1f\u8bf7\u6c42\u662f\u7531\u8ba1\u7b97\u673a\u4e2d\u67d0\u4e2a\u8fdb\u7a0b\u6839\u636e\u7279\u5b9a\u7684\u6307\u4ee4\u6765\u5904\u7406\u7684\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u8fd9\u4e00\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\uff0c\u5f53\u670d\u52a1\u5668\u6536\u5230\u4e00\u4e2a\u8bf7\u6c42\u540e\uff0c\u4f1a\u6709\u4e00\u4e2a\u8fdb\u7a0b\u6765\u5904\u7406\u5b83\uff0c\u628a\u8fd9\u4e2a\u8bf7\u6c42\u7ecf\u8fc7\u62e6\u622a\u5668\u7b49\u7b49\u4e0d\u540c\u7684\u5904\u7406\u7a0b\u5e8f\uff0c\u7ec8\u4e8e\u6765\u5230\u4e86\u63a7\u5236\u5668\u4e86\uff0c\u63a7\u5236\u5668\u5bf9\u5b83\u8fdb\u884c\u4e86\u4e00\u4e9b\u5904\u7406\uff0c\u7136\u540e\u53c8\u628a\u5b83\u4ea4\u7ed9\u4e0b\u4e00\u6b65\u7684\u7a0b\u5e8f\u5904\u7406\uff08\u5b9e\u9645\u4e0a\u7684\u5b9e\u65bd\u4e3b\u4f53\u662f\u8fdb\u7a0b\uff09\uff0c\u7ecf\u8fc7\u4e00\u4e9b\u5904\u7406\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u53eb\u5904\u7406\u8fc7\u540e\u7684\u6570\u636e\u4e3a\u54cd\u5e94\u4e86\uff0c\u8fdb\u7a0b\u628a\u8fd9\u4e9b\u6570\u636e\u53d1\u9001\u5230\u67d0\u4e2a\u63a5\u53d7\u7684\u5730\u65b9\uff0c\u4e00\u6b21Http\u8bf7\u6c42\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u771f\u6b63\u64cd\u4f5c\u7684\u662f\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u4ee3\u7801\u662f\u5b58\u653e\u5728\u5185\u5b58\u4e2d\u7684\u4e00\u6bb5\u4e00\u6bb5\u6570\u636e\uff0c\u8fdb\u7a0b\u4ece\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u4e5f\u8bb8\u4f1a\u5bf9\u5176\u4e2d\u7684\u67d0\u4e9b\u6570\u636e\u8fdb\u884c\u4fee\u6539\uff08\u8fd9\u91cc\u5c31\u6d89\u53ca\u5230\u4e86\u591a\u7ebf\u7a0b\u7684\u5b89\u5168\u95ee\u9898\uff09\u3002<\/p>\n\n\n\n<p>\u800c\u8fd9\u4e00\u6b21\u5904\u7406\u8bf7\u6c42\u5e76\u8fd4\u56de\u54cd\u5e94\u7684\u8fc7\u7a0b\uff0c\u5728\u5b9e\u9645\u4e2d\u64cd\u4f5c\u7684\u662f\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5b83\u5728\u4e3b\u8fdb\u7a0b\u4e2d\u521b\u5efa\uff0c\u7528\u4e8e\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p>Spring mvc\u7684controller\u7684\u540c\u4e00\u4e2a\u63a5\u53e3\u540c\u65f6\u63a5\u53d7\u591a\u4e2a\u8bf7\u6c42\u65f6\uff0c\u7a0b\u5e8f\u6267\u884c\u662f\u5e76\u53d1\u7684\u3002\u7ebf\u7a0b\u662f\u7531web\u5bb9\u5668\u521b\u5efa\u7684\uff0c\u800c\u4e0d\u662fspring\u3002\u4e00\u4e2a\u8bf7\u6c42\u8fc7\u6765\u7531\u5bb9\u5668\u5176\u4e00\u4e2a\u7ebf\u7a0b\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9DisoatcherServelet\u5904\u7406\uff0c\u5b83\u6839\u636eHadlerMapping\u518d\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9controller,\u8fd9\u624d\u5230\u4e86\u6211\u4eec\u719f\u6089\u7684mvc\u90e8\u5206\u3002\u6240\u4ee5\uff0cHTTP\u5e76\u53d1\u8bf7\u6c42\u662f\u7531\u5bb9\u5668\u8d1f\u8d23\u5206\u914d\u7ebf\u7a0b\u5904\u7406\u7684\u3002<\/p>\n\n\n\n<p>spring\u7ba1\u7406\u7684\u5bf9\u8c61\u9ed8\u8ba4\u90fd\u662f\u5355\u4f8b\uff0c\u6240\u4ee5\u591a\u7ebf\u7a0b\u8bbf\u95ee\u540c\u4e00\u8d44\u6e90\uff08\u53ef\u80fd\u662fcontroller\u6216\u8005service\u6216\u8005dao\u4e2d\u7684\u6210\u5458\u53d8\u91cf\uff09\uff0c\u5fc5\u7136\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002\u6240\u4ee5\u9700\u8981\u7528\u5230\u7684\u53d8\u91cf\u5c3d\u91cf\u653e\u5230\u65b9\u6cd5\u4e2d\u3002\u56e0\u4e3a\u65b9\u6cd5\u4e2d\u7684\u53d8\u91cf\u5206\u914d\u5185\u5b58\u65f6\uff0c\u662f\u5206\u914d\u5230\u5f53\u524d\u7ebf\u7a0b\u7684\u6808\u4e2d\u7684\u5f53\u524d\u65b9\u6cd5\u7684\u6808\u5e27\u4e2d\u3002\u5c5e\u4e8e\u7ebf\u7a0b\u79c1\u6709\u53d8\u91cf\uff0c\u6240\u4ee5\u4e0d\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"309\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-1024x309.png\" alt=\"\" class=\"wp-image-14598\" style=\"width:506px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-1024x309.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-300x90.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-768x231.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-830x250.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-230x69.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-350x105.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38-480x145.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-38.png 1394w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"562\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-1024x562.png\" alt=\"\" class=\"wp-image-14599\" style=\"width:484px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-1024x562.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-300x165.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-768x422.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-830x456.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-230x126.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-350x192.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39-480x264.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-39.png 1406w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><br><\/p>\n\n\n\n<p><strong>\u5f53\u591a\u4e2a\u8bf7\u6c42\u540c\u65f6\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u65f6\u5019<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u73b0\u5728\uff0c\u6709\u591a\u4e2a\u8bf7\u6c42\u540c\u65f6\u8bbf\u95ee\u670d\u52a1\u5668\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u6709\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\uff0c\u7ebf\u7a0b\u7531\u670d\u52a1\u5668\u7a0b\u5e8f\u6765\u521b\u5efa\uff08\u4f8b\u5982SpringBoot\u9ed8\u8ba4\u4f7f\u7528\u7684Tomcat\uff09\uff0c\u7ebf\u7a0b\u6839\u636e\u5185\u5b58\u4e2d\u7684\u4ee3\u7801\uff08\u4ee3\u7801\u76f8\u5f53\u4e8e\u8bf4\u660e\u4e66\uff09\u6267\u884c\u4e0b\u53bb\uff0c\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u53ef\u4ee5\u8bbf\u95ee\u5230Controller\u4e2d\u7684\u4ee3\u7801\uff0c\u5982\u679cController\u53ea\u6709\u4e00\u4e2a\u7684\u8bdd\uff0c\u90a3\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u8bbf\u95ee\u8fd9\u4e2aController\uff0c\u6839\u636e\u5b83\u7684\u4ee3\u7801\u6765\u6267\u884c\u3002\u4ee3\u7801\u5c31\u50cf\u662f\u4e00\u4efd\u8bf4\u660e\u4e66\uff0c\u65e0\u8bba\u591a\u5c11\u7684\u8bf7\u6c42\uff0c\u90fd\u6309\u7167\u540c\u4e00\u4efd\u8bf4\u660e\u4e66\u6765\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u77e5\u9053\u4e86\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u662f\u7531\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5904\u7406\uff0c\u6211\u4eec\u4e5f\u5c31\u53ef\u4ee5\u660e\u767d\u4e00\u4e2a\u670d\u52a1\u5668\u540c\u65f6\u80fd\u591f\u5904\u7406\u7684\u8bf7\u6c42\u6570\u4e0e\u5b83\u7684\u7ebf\u7a0b\u6570\u6709\u5f88\u5927\u7684\u5173\u7cfb\u3002\u7ebf\u7a0b\u7684\u521b\u5efa\u662f\u6bd4\u8f83\u6d88\u8017\u8d44\u6e90\u7684\uff0c\u6240\u4ee5\u5bb9\u5668\u4e00\u822c\u7ef4\u6301\u4e00\u4e2a\u7ebf\u7a0b\u6c60\u3002\u50cfTomcat\u7684\u7ebf\u7a0b\u6c60 maxThreads \u662f200\uff0c minSpareThreads \u662f25\u3002\u5b9e\u9645\u4e2d\u5355\u4e2aTomcat\u670d\u52a1\u5668\u7684\u6700\u5927\u5e76\u53d1\u6570\u53ea\u6709\u51e0\u767e\uff0c\u90e8\u5206\u539f\u56e0\u5c31\u662f\u53ea\u80fd\u540c\u65f6\u5904\u7406\u8fd9\u4e48\u591a\u7ebf\u7a0b\u4e0a\u7684\u4efb\u52a1\u3002\u5f53\u7136\uff0c\u5e76\u53d1\u7684\u9650\u5236\u80af\u5b9a\u4e0d\u6b62\u5728\u8fd9\u91cc\uff0c\u8fd8\u6709\u5f88\u591a\u9700\u8981\u8003\u8651\u7684\u5730\u65b9\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u5e94\u5bf9\u8bf7\u6c42\u5206\u914d\u7ebf\u7a0b\u5904\u7406\u7684\u662fservlet\u5bb9\u5668\uff08\u4e5f\u5c31\u662ftomcat\u7b49\u670d\u52a1\u5668\u7a0b\u5e8f\uff09\u3002<\/p>\n\n\n\n<p><strong>Controller\u3001Service\u3001DAO\u7b49\u7c7b\u90fd\u9ed8\u8ba4\u4e3a\u5355\u4f8b\u6a21\u5f0f<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053\uff0c Controller\u3001Service\u3001DAO\u90fd\u662f\u9ed8\u8ba4\u4e3a\u5355\u4f8b\u6a21\u5f0f\u7684\uff0c<\/p>\n\n\n\n<p>\u53c8\u56e0\u4e3a\uff0c\u5982\u679c\u4e00\u4e2a\u7c7b\u65e0\u8bba\u4ec0\u4e48\u65f6\u5019\u90fd\u4e0d\u4f1a\u6539\u53d8\uff0c\u90a3\u4e48\u5b83\u5c31\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u65e0\u8bba\u591a\u5c11\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\uff0c\u90fd\u4f1a\u5f97\u5230\u76f8\u540c\u7684\u7ed3\u679c\uff0c\u4e0d\u4f1a\u6709\u4efb\u4f55\u5f71\u54cd\uff0c\u4e0d\u7528\u8003\u8651\u591a\u7ebf\u7a0b\u5e26\u6765\u7684\u5f71\u54cd\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u5728Controller\u3001Service\u3001DAO\u5c3d\u91cf\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\uff0c\u4e0d\u8981\u4f7f\u7528\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff0c\u5982\u679c\u4f7f\u7528\u7684\u8bdd\uff0c\u8bb0\u5f97\u4e00\u5b9a\u8981\u52a0\u9501\u3002<\/p>\n\n\n\n<p>\u63a7\u5236\u5668\u4e2d\u5982\u679c\u6ca1\u6709\u7ef4\u6301\u53ef\u53d8\u7684\u6210\u5458\u53d8\u91cf\uff0c\u4e5f\u7c7b\u4f3c\u4e8e\u4e0d\u53ef\u53d8\u7c7b\uff0c\u5b83\u5728\u591a\u7ebf\u7a0b\u60c5\u51b5\u4e0b\u4e5f\u4e0d\u9700\u8981\u591a\u8003\u8651\uff0c\u548c\u5728\u5355\u7ebf\u7a0b\u4e0b\u533a\u522b\u4e0d\u5927\uff0c\u5f53\u7136\u8fd9\u4e00\u822c\u4e0d\u4f1a\u53d1\u751f\u3002\u6211\u4eec\u7ecf\u5e38\u5728\u5176\u4e2d\u5b9a\u4e49\u8bb8\u591aService\uff0c\u5728\u5bb9\u5668\u542f\u52a8\u7684\u65f6\u5019\u8fd9\u4e9bService\u88ab\u6ce8\u5165\u8fdb\u6765\uff0c\u7528\u6237\u4f20\u5165\u7684\u8bf7\u6c42\u5927\u90e8\u5206\u5728\u8fd9\u91cc\u548c\u670d\u52a1\u5668\u8fdb\u884c\u4ea4\u4e92\uff0c\u6bd4\u5982\u67e5\u770b\u5f53\u524d\u662f\u5426\u767b\u5f55\uff0c\u8bf7\u6c42\u67e5\u770b\u7528\u6237\u4fe1\u606f\u7b49\u7b49\uff0c\u6839\u636eController\u4e2d\u7684\u4ee3\u7801\uff0c\u8c03\u7528\u4e0d\u540c\u7684Service\u5bf9\u8fd9\u4e9b\u4fe1\u606f\u8fdb\u884c\u5904\u7406\u3002\u8fd9\u91cc\u5c31\u8981\u8003\u8651\u5230\u7ebf\u7a0b\u5b89\u5168\u7684\u95ee\u9898\u4e86\u3002<\/p>\n\n\n\n<p><strong>Controller\u3001Service\u3001DAO\u7b49\u7c7b\u4e2d\u7684\u65b9\u6cd5\u5f53\u4e2d\u7684\u5e76\u53d1\u95ee\u9898<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5c3d\u7ba1 Controller\u3001Service\u3001DAO\u90fd\u662f\u9ed8\u8ba4\u4e3a\u5355\u4f8b\u6a21\u5f0f\u7684\uff0c<\/p>\n\n\n\n<p>\u4f46\u662f\u6bcf\u4e2a\u65b9\u6cd5\u5728\u8c03\u7528\u6808\u91cc\u90fd\u4f1a\u6709\u81ea\u5df1\u72ec\u7acb\u7684\u6808\u5e27\uff0c\u6bcf\u4e2a\u6808\u5e27\u91cc\u90fd\u6709\u5bf9\u5e94\u65b9\u6cd5\u9700\u8981\u7684\u53c2\u6570\u548c\u8fd4\u56de\u5730\u5740\u3002\u5f53\u8c03\u7528\u65b9\u6cd5\u65f6\uff0c\u4f1a\u521b\u5efa\u65b0\u7684\u6808\u5e27\uff0c\u5e76\u538b\u5165\u8c03\u7528\u6808\uff1b\u5f53\u65b9\u6cd5\u8fd4\u56de\u65f6\uff0c\u5bf9\u5e94\u7684\u6808\u5e27\u5c31\u4f1a\u88ab\u81ea\u52a8\u5f39\u51fa\u3002<\/p>\n\n\n\n<p>\u6808\u5e27\u662f\u5728\u8c03\u7528\u65b9\u6cd5\u65f6\u521b\u5efa\uff0c\u65b9\u6cd5\u8fd4\u56de\u65f6\u201c\u6d88\u4ea1\u201d\u3002<\/p>\n\n\n\n<p>\u5c40\u90e8\u53d8\u91cf\u5b58\u653e\u5728\u54ea\u91cc\uff1f<br>\u5c40\u90e8\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u5728\u65b9\u6cd5\u5185\u90e8\uff0c\u5f53\u65b9\u6cd5\u6267\u884c\u5b8c\uff0c\u5c40\u90e8\u53d8\u91cf\u4e5f\u5c31\u6ca1\u7528\u4e86\u3002\u53ef\u4ee5\u8fd9\u4e48\u8bf4\uff0c\u65b9\u6cd5\u8fd4\u56de\u65f6\uff0c\u5c40\u90e8\u53d8\u91cf\u4e5f\u5c31\u201c\u6d88\u4ea1\u201d\u4e86\u3002\u6b64\u65f6\uff0c\u6211\u4eec\u4f1a\u8054\u60f3\u5230\u8c03\u7528\u6808\u7684\u6808\u5e27\u3002\u6ca1\u9519\uff0c\u5c40\u90e8\u53d8\u91cf\u5c31\u662f\u5b58\u653e\u5728\u8c03\u7528\u6808\u91cc\u7684\u3002\u6b64\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u65b9\u6cd5\u7684\u8c03\u7528\u6808\u7528\u4e0b\u56fe\u8868\u793a\u3002<\/p>\n\n\n\n<p>\u7ebf\u7a0b\u5c01\u95ed<br>\u65b9\u6cd5\u91cc\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u56e0\u4e3a\u4e0d\u4f1a\u548c\u5176\u4ed6\u7ebf\u7a0b\u5171\u4eab\uff0c\u6240\u4ee5\u4e0d\u4f1a\u5b58\u5728\u5e76\u53d1\u95ee\u9898\u3002\u8fd9\u79cd\u89e3\u51b3\u95ee\u9898\u7684\u6280\u672f\u4e5f\u53eb\u505a\u7ebf\u7a0b\u5c01\u95ed\u3002\u4ec5\u5728\u5355\u7ebf\u7a0b\u5185\u8bbf\u95ee\u6570\u636e\u3002\u7531\u4e8e\u4e0d\u5b58\u5728\u5171\u4eab\uff0c\u6240\u4ee5\u5373\u4f7f\u4e0d\u8bbe\u7f6e\u540c\u6b65\uff0c\u4e5f\u4e0d\u4f1a\u51fa\u73b0\u5e76\u53d1\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u5728Controller\u3001Service\u3001DAO\u5c3d\u91cf\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\uff0c\u4e0d\u8981\u4f7f\u7528\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff0c\u5982\u679c\u4f7f\u7528\u7684\u8bdd\uff0c\u8bb0\u5f97\u4e00\u5b9a\u8981\u6839\u636e\u4e1a\u52a1\u903b\u8f91\u6765\u5224\u65ad\u662f\u5426\u8981\u52a0\u9501\u3002<\/p>\n\n\n\n<p><strong>Controller\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684(\u5355\u4f8b\uff0c\u5b58\u5728\u6210\u5458\u53d8\u91cf\u65f6\u51fa\u73b0\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898)<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u6b63\u56e0\u4e3aController\u9ed8\u8ba4\u662f\u5355\u4f8b\uff0c\u6240\u4ee5\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002\u5982\u679c\u7528SpringMVC \u7684 Controller\u65f6\uff0c\u5c3d\u91cf\u4e0d\u5728 Controller\u4e2d\u4f7f\u7528\u5b9e\u4f8b\u53d8\u91cf\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u7ebf\u7a0b\u4e0d\u5b89\u5168\u6027\u7684\u60c5\u51b5\uff0c\u5bfc\u81f4\u6570\u636e\u903b\u8f91\u6df7\u4e71\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u5728\u4e00\u4e2aController\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u975e\u9759\u6001\u6210\u5458\u53d8\u91cf num \u3002\u901a\u8fc7Controller\u6210\u5458\u65b9\u6cd5\u6765\u5bf9 num \u589e\u52a0\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=\"\">@Controller\npublic class TestController {\n    private int num = 0;\n    \n    @RequestMapping(\"\/addNum\")\n    public void addNum() {\n        System.out.println(++num);\n    }\n}\n<\/pre>\n\n\n\n<p>\u5728\u672c\u5730\u8fd0\u884c\u540e\uff1a<\/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=\"\">\u9996\u5148\u8bbf\u95ee http:\/\/ localhost:8080 \/ addNum\uff0c\u5f97\u5230\u7684\u7b54\u6848\u662f1\uff1b\n\u518d\u6b21\u8bbf\u95ee http:\/\/ localhost:8080 \/ addNum\uff0c\u5f97\u5230\u7684\u7b54\u6848\u662f 2\u3002\n\u4e24\u6b21\u8bbf\u95ee\u5f97\u5230\u7684\u7ed3\u679c\u4e0d\u540c\uff0cnum\u5df2\u7ecf\u88ab\u4fee\u6539\uff0c\u5e76\u4e0d\u662f\u6211\u4eec\u5e0c\u671b\u7684\u7ed3\u679c\uff0c\u63a5\u53e3\u7684\u5e42\u7b49\u6027\u88ab\u7834\u574f\u3002<\/pre>\n\n\n\n<p>\u4ece\u8fd9\u4e2a\u4f8b\u5b50\u53ef\u4ee5\u770b\u51fa\uff0c\u6240\u6709\u7684\u8bf7\u6c42\u8bbf\u95ee\u540c\u4e00\u4e2aController\u5b9e\u4f8b\uff0cController\u7684\u79c1\u6709\u6210\u5458\u53d8\u91cf\u5c31\u662f\u7ebf\u7a0b\u5171\u7528\u7684\u3002\u67d0\u4e2a\u8bf7\u6c42\u5bf9\u5e94\u7684\u7ebf\u7a0b\u5982\u679c\u4fee\u6539\u4e86\u8fd9\u4e2a\u53d8\u91cf\uff0c\u90a3\u4e48\u5728\u522b\u7684\u8bf7\u6c42\u4e2d\u4e5f\u53ef\u4ee5\u8bfb\u5230\u8fd9\u4e2a\u53d8\u91cf\u4fee\u6539\u540e\u7684\u7684\u503c\u3002<br><\/p>\n\n\n\n<p><strong>\u5173\u4e8eDAO\u5e76\u53d1\u8bbf\u95ee\u6570\u636e\u7684\u95ee\u9898<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u5047\u8bbe\u4e00\u4e2a\u4f8b\u5b50\uff0c\u73b0\u5728\u8981\u505a\u4e00\u4e2a\u7528\u6237\u6ce8\u518c\u670d\u52a1\uff0c\u7528\u6237\u6ce8\u518c\u9700\u8981\u7ed1\u5b9a\u624b\u673a\u53f7\u7801\uff0c\u56e0\u6b64\uff0c\u6ce8\u518c\u7684\u4e1a\u52a1\u903b\u8f91\u4e2d\u5fc5\u987b\u8981\u6709\u4e00\u4e2a\u5224\u65ad\uff0c\u4e5f\u5c31\u662f\u5224\u65ad\u8be5\u624b\u673a\u53f7\u7801\u6709\u6ca1\u6709\u88ab\u6ce8\u518c\uff0c\u8fd9\u9700\u8981DAO\u5c42\u53bb\u6570\u636e\u5e93\u67e5\u8be2\u662f\u5426\u6709\u62e5\u6709\u8be5\u624b\u673a\u53f7\u7801\u7684\u8bb0\u5f55\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u6709\u4e24\u4e2a\u6ce8\u518c\u8bf7\u6c42\u540c\u65f6\u53d1\u51fa\uff0c\u5e26\u7740\u4e00\u6837\u7684\u7535\u8bdd\u53f7\u7801\u3002\u8fd9\u4e24\u4e2a\u8bf7\u6c42\u540c\u65f6\u5230\u8fbeTomcat\u670d\u52a1\u5668\uff0c\u5728\u4e24\u4e2a\u7ebf\u7a0b\u5185\u540c\u65f6\u8c03\u7528Controller\uff0c\u5728DAO\u5c42\u67e5\u8be2\u7535\u8bdd\u53f7\u7801\u7684\u7ed3\u679c\u90fd\u662f\u201c\u8be5\u624b\u673a\u53f7\u7801\u6ca1\u6709\u88ab\u6ce8\u518c\u201d\uff0c\u4e8e\u662f\u90fd\u7528\u8be5\u7535\u8bdd\u53f7\u7801\u8fdb\u884c\u4e86\u6ce8\u518c\uff0c\u4f46\u662f\u7531\u4e8e\u6570\u636e\u5e93\u5e93\u4e2d\uff0c\u7528\u6237\u8868\u4e2d\uff0c\u7535\u8bdd\u53f7\u7801\u8fd9\u4e2a\u5c5e\u6027\u88ab\u8bbe\u7f6e\u4e86unique key\uff0c\u6240\u4ee5\u8fd9\u4e24\u4e2a\u6ce8\u518c\u8bf7\u6c42\u4e00\u5b9a\u4f1a\u6709\u4e00\u4e2a\u8bf7\u6c42\u53d1\u751f\u5f02\u5e38\uff0c\u56e0\u6b64\uff0c\u505a\u8fd9\u79cd\u529f\u80fd\u7684\u65f6\u5019\u4e00\u5b9a\u8981\u52a0\u4e0a\u5f02\u5e38\u5904\u7406\u3002<\/p>\n\n\n\n<p>**\u5355\u4f8b\u6a21\u5f0f\uff08Singleton\uff09**\u662f\u7a0b\u5e8f\u8bbe\u8ba1\u4e2d\u4e00\u79cd\u975e\u5e38\u91cd\u8981\u7684\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u8bbe\u8ba1\u6a21\u5f0f\u4e5f\u662fJava\u9762\u8bd5\u91cd\u70b9\u8003\u5bdf\u7684\u4e00\u4e2a\u65b9\u9762\u3002\u9762\u8bd5\u7ecf\u5e38\u4f1a\u95ee\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u662f\uff1aSpringMVC\u4e2d\u7684Controller\u662f\u5355\u4f8b\u8fd8\u662f\u591a\u4f8b\uff0c\u5f88\u591a\u540c\u5b66\u53ef\u80fd\u4f1a\u60f3\u5f53\u7136\u8ba4\u4e3aController\u662f\u591a\u4f8b\uff0c\u5176\u5b9e\u4e0d\u7136\u3002<\/p>\n\n\n\n<p>\u6839\u636eTomcat\u5b98\u7f51\u4e2d\u7684\u4ecb\u7ecd\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u6d4f\u89c8\u5668\u8bf7\u6c42\uff0ctomcat\u4f1a\u6307\u5b9a\u4e00\u4e2a\u5904\u7406\u7ebf\u7a0b\uff0c\u6216\u662f\u5728\u7ebf\u7a0b\u6c60\u4e2d\u9009\u53d6\u7a7a\u95f2\u7684\uff0c\u6216\u8005\u65b0\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u3002<\/p>\n\n\n\n<p>\u5728Tomcat\u5bb9\u5668\u4e2d\uff0c\u6bcf\u4e2aservlet\u662f\u5355\u4f8b\u7684\u3002<strong>\u5728SpringMVC\u4e2d\uff0cController \u9ed8\u8ba4\u4e5f\u662f\u5355\u4f8b\u3002<\/strong>\u91c7\u7528\u5355\u4f8b\u6a21\u5f0f\u7684\u6700\u5927\u597d\u5904\uff0c\u5c31\u662f\u53ef\u4ee5\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b\u6781\u5927\u5730\u8282\u7701\u5185\u5b58\u8d44\u6e90\uff0c\u63d0\u9ad8\u670d\u52a1\u6297\u538b\u80fd\u529b\u3002<\/p>\n\n\n\n<p>\u5355\u4f8b\u6a21\u5f0f\u5bb9\u6613\u51fa\u73b0\u7684\u95ee\u9898\u662f\uff1a\u5728Controller\u4e2d\u5b9a\u4e49\u7684\u5b9e\u4f8b\u53d8\u91cf\uff0c\u5728\u591a\u4e2a\u8bf7\u6c42\u5e76\u53d1\u65f6\u4f1a\u51fa\u73b0\u7ade\u4e89\u8bbf\u95ee\uff0cController\u4e2d\u7684\u5b9e\u4f8b\u53d8\u91cf\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/p>\n\n\n\n<p><strong>\u5173\u4e8econtroller\u7684\u4e00\u70b9\u7591\u95ee<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cspring\u4e2d\u7684controller\u662f\u5355\u4f8b\u6a21\u5f0f\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u6240\u6709\u7684\u8bbf\u95ee\u90fd\u4f1a\u8c03\u7528\u540c\u4e00\u4e2acontroller\u7684\u65b9\u6cd5\uff0c\u81ea\u7136\u800c\u7136\u7684\u5c31\u4f1a\u60f3\u5230\u5e76\u53d1\u7684\u95ee\u9898\uff0c\u5f53\u67d0\u4e00\u4e2a\u8bf7\u6c42\u8c03\u7528controller\u65b9\u6cd5\u5c1a\u672a\u9000\u51fa\u65f6\uff0c\u662f\u5426\u4f1a\u9020\u6210\u540e\u7eed\u8bf7\u6c42\u7684\u963b\u585e\u3002<br>\u5199\u4e2a\u5c0fdemo\u6d4b\u8bd5\u4e00\u4e0b<\/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=\"\">\t@RequestMapping(\"\/dotest01\/{id}\")\n\t@ResponseBody\n\tpublic String dotest01(@PathVariable(\"id\") int id) {\n\t\tlong start =System.currentTimeMillis();\n\t\tString str;\n\t\tif(id==1) {\n\t\t\ttry {\n\t\t\t\tThread.sleep(4000);\n\t\t\t} catch (InterruptedException e) {\n\t\t\t\t\/\/ TODO Auto-generated catch block\n\t\t\t\te.printStackTrace();\n\t\t\t}\n\t\t\tlog.info(\"1\u53f7\"+Thread.currentThread().getName());\n\t\t\tlog.info(this.toString());\n\t\t\tstr=\"1\u53f7\u7ed3\u679c\uff01\";\n\t\t}else {\n\t\t\tlog.info(\"2\u53f7\"+Thread.currentThread().getName());\n\t\t\tlog.info(this.toString());\n\t\t\tstr=\"2\u53f7\u7ed3\u679c\";\n\t\t}\n\t\tlong time =System.currentTimeMillis()-start;\n\t\treturn str+time;\n\t}\n<\/pre>\n\n\n\n<p><br>\u8fdb\u884c\u6d4b\u8bd5\u5148\u53d1\u9001\u8bbf\u95eedotest01\/1\uff0c\u540e\u8bbf\u95eedotest01\/2\uff0c\u5f88\u660e\u663e\u7b2c\u4e00\u4e2a\u9875\u9762\u5c1a\u5728\u52a0\u8f7d\uff0c\u7b2c\u4e8c\u4e2a\u5c31\u5df2\u7ecf\u8fd4\u56de<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-1024x540.png\" alt=\"\" class=\"wp-image-14592\" style=\"width:486px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-1024x540.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-300x158.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-768x405.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-830x437.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-230x121.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-350x184.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34-480x253.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-34.png 1146w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u518d\u770b\u770b\u540e\u5934\u7684\u5bf9\u8c61<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"166\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-1024x166.png\" alt=\"\" class=\"wp-image-14593\" style=\"width:506px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-1024x166.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-300x49.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-768x125.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-830x135.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-230x37.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-350x57.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35-480x78.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-35.png 1182w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u5f88\u660e\u663e\uff0c\u7ebf\u7a0b\u662f\u5355\u72ec\u7684\u4f46\u662fcontroller\u662f\u540c\u4e00\u4e2a\u3002<br>\u53ef\u4ee5\u786e\u8ba4\u7684\u662f\uff0c\u4e0d\u7528\u8003\u8651controller\u7684\u963b\u585e\u95ee\u9898\uff0c\u518d\u5199\u4e00\u4e2a\u591a\u7ebf\u7a0b\u6d4b\u8bd5\u6848\u4f8b<\/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=\"\">public class TestThread {\n\tpublic static void main(String[] args) {\n\t\tMyTool tool = new MyTool();\n\t\tnew Thread(new MyThread(0, tool)).start();\n\t\tnew Thread(new MyThread(1, tool)).start();\n\t}\n}\n\nclass MyThread implements Runnable {\n\t\n\tprivate int id;\n\t\n\tprivate MyTool tool;\n\t\n\tpublic MyThread(int id,MyTool tool) {\n\t\tthis.id=id;\n\t\tthis.tool=tool;\n\t}\n\t\n\tpublic void run() {\n\t\tlong start = System.currentTimeMillis();\n\t\tSystem.out.println(\"Thred:\"+Thread.currentThread().getName()+\"==\"+tool.toString());\n\t\ttool.dosome(id);\n\t\tlong time = System.currentTimeMillis()-start;\n\t\tSystem.out.println(\"id\"+id+\"==time=\"+time);\n\t}\n}\n\n class MyTool {\n\tpublic void dosome(int id) {\n\t\tif(id ==0) {\n\t\tSystem.out.println(\"00\u5f00\u59cb\u5de5\u4f5c\uff01\");\n\t\ttry {\n\t\t\tThread.sleep(1000);\n\t\t} catch (InterruptedException e) {\n\t\t\t\/\/ TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\t\tSystem.out.println(\"00\u5de5\u4f5c\u5b8c\u6210\uff01\");\n\t\t}else {\n\t\t\tSystem.out.println(\"01\u5f00\u59cb\u5de5\u4f5c\uff01\");\n\t\t\tSystem.out.println(\"01\u5de5\u4f5c\u5b8c\u6210\uff01\");\n\t\t}\t\t\n\t}\n}\n<\/pre>\n\n\n\n<p>\u6d4b\u8bd5\u7ed3\u679c\u4e3a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"308\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-1024x308.png\" alt=\"\" class=\"wp-image-14594\" style=\"width:482px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-1024x308.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-300x90.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-768x231.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-830x250.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-230x69.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-350x105.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36-480x144.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-36.png 1276w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u7b26\u5408\u671f\u671b\uff0c\u5de5\u4f5c\u7ebf\u7a0b\u4e0d\u540c\uff0c\u5de5\u4f5c\u5bf9\u8c61\u540c\u4e00\u4e2a\u3002\u5728\u4fee\u6539\u4e00\u4e0b<\/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=\"\">public synchronized void dosome(int id){\n\t\t.....\n}\n<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1018\" height=\"368\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37.png\" alt=\"\" class=\"wp-image-14595\" style=\"width:446px;height:auto\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37.png 1018w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37-300x108.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37-768x278.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37-830x300.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37-230x83.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37-350x127.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/05\/image-37-480x174.png 480w\" sizes=\"(max-width: 1018px) 100vw, 1018px\" \/><\/figure><\/div>\n\n\n<p>\u4e3a\u65b9\u6cd5\u52a0\u4e0a\u9501\uff0c\u8fd9\u65f6\u5019\u5c31\u4e0d\u540c\u4e86<\/p>\n\n\n\n<p>\u6b64\u65f6\u7ebf\u7a0b\u624d\u4f1a\u963b\u585e\uff0c\u8bf4\u5230\u5e95\u5bf9\u963b\u585e\u7684\u6982\u5ff5\u6709\u70b9\u6df7\u4e71\uff0c\u591a\u7ebf\u7a0b\u662f\u53ef\u4ee5\u540c\u65f6\u8bbf\u95ee\u901a\u4e00\u4e2a\u4e0d\u52a0\u9501\u65b9\u6cd5\uff0c\u6240\u8c13\u989d\u5e76\u53d1\u95ee\u9898\u662f\u591a\u7ebf\u7a0b\u64cd\u4f5c\u9020\u6210\u7684\u6570\u636e\u6df7\u4e71\uff0c\u963b\u585e\u662f\u52a0\u9501\u9020\u6210\u7684\uff0c\u5f88\u663e\u7136controller\u5e76\u672a\u7ed9\u65b9\u6cd5\u52a0\u9501\uff0c\u6240\u4ee5\u5e76\u4e0d\u4f1a\u6709\u963b\u585e\u7684\u95ee\u9898\u3002<br>\u4f46\u662f\u4e5f\u5f97\u6ce8\u610f\uff0c\u5728controller\u4e2d\u521b\u5efa\u5168\u5c40\u53d8\u91cf\u8fd9\u65f6\u5019\u5c31\u8981\u8003\u8651\u5e76\u53d1\u95ee\u9898\u4e86\u3002<\/p>\n\n\n\n<p><strong>Springboot\u4e2d\u7684\u5b9a\u65f6\u4efb\u52a1\u662f\u5426\u4f1a\u53d1\u751f\u963b\u585e?<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Springboot\u4e2d\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u6ca1\u6267\u884c\u5b8c\uff0c\u662f\u5426\u4f1a\u5f71\u54cd\u4e0b\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u6267\u884c\uff1f<\/p>\n\n\n\n<p>\u5728springboot\u4e2d\u4f7f\u7528\u5b9a\u65f6\u4efb\u52a1\u7684\u6b65\u9aa4<\/p>\n\n\n\n<p>1.\u5728\u542f\u52a8\u7c7b\u4e0a\u52a0\u4e0a\u6ce8\u89e3\uff1a@EnableScheduling\uff0c\u8868\u793a\u5141\u8bb8\u5b9a\u65f6\u4efb\u52a1\u6267\u884c<\/p>\n\n\n\n<p>2.\u5b9a\u65f6\u4efb\u52a1\u9700\u8981\u5728\u7c7b\u4e0a\u52a0\u4e0a@Component\u6216\u8005\u5176\u884d\u751f\u7c7b\uff08Controller\u3001Service\u7b49\uff09\uff0c\u7528\u4e8e\u7eb3\u5165Spring\u5bb9\u5668\u7ba1\u7406\u3002<\/p>\n\n\n\n<p>3.\u5728\u9700\u8981\u5b9a\u65f6\u4efb\u52a1\u65b9\u6cd5\u4e0a\u589e\u52a0\u6ce8\u89e3@Scheduled\uff0c\u6ce8\u89e3\u7684\u53c2\u6570\u662f\u5b9a\u65f6\u4efb\u52a1\u6267\u884c\u65f6\u673a<\/p>\n\n\n\n<p>\u9996\u5148\u9700\u8981\u77e5\u9053\uff1a\u5b9a\u65f6\u4efb\u52a1\u9ed8\u8ba4\u662f\u5355\u7ebf\u7a0b\u7684\u3002\u6240\u4ee5\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4e0a\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u6ca1\u6709\u6267\u884c\u5b8c\uff0c\u4e0b\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u662f\u4e0d\u4f1a\u5f00\u59cb\u7684\u3002<\/p>\n\n\n\n<p>\u7ed3\u8bba\uff1a<\/p>\n\n\n\n<ul>\n<li>1.\u5b9a\u65f6\u4efb\u52a1\u9ed8\u8ba4\u662f\u5355\u7ebf\u7a0b\u7684\u3002\u5982\u679c\u4efb\u52a1\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u5b9a\u65f6\u4efb\u52a1\u95f4\u9694\u65f6\u95f4\uff0c\u4e0d\u7ba1\u662f\u540c\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u8fd8\u662f\u4e0d\u540c\u7684\u5b9a\u65f6\u4efb\u52a1\uff0c\u4e0b\u4e00\u4e2a\u4efb\u52a1\u90fd\u4f1a\u88ab\u963b\u585e\u3002<\/li>\n\n\n\n<li>2.\u5b9e\u73b0SchedulingConfigurer\u63a5\u53e3\u540e\uff0c\u5b9a\u65f6\u4efb\u52a1\u4f1a\u53d8\u6210\u591a\u7ebf\u7a0b\u6267\u884c\u3002\u4e0d\u540c\u7684\u5b9a\u65f6\u4efb\u52a1\u4e4b\u95f4\u4e92\u4e0d\u5f71\u54cd\uff0c\u540c\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\uff08\u65b9\u6cd5\uff09\u4f9d\u7136\u4f1a\u6709\u88ab\u963b\u585e\u7684\u673a\u5236\u3002<\/li>\n\n\n\n<li>3.\u5982\u679c\u5b9a\u65f6\u4efb\u52a1\u4ea4\u7ed9\u7ebf\u7a0b\u6c60\u5904\u7406\uff0c\u5219\u4e0b\u4e00\u4e2a\u4efb\u52a1\u4e0d\u4f1a\u88ab\u963b\u585e\u3002<\/li>\n<\/ul>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898 SpringMVC\u4e2d\u7528\u6765\u5904\u7406http\u8bf7\u6c42\u7684Controller\u662f\u57fa\u4e8eServlet\u5b9e\u73b0\u7684\uff0cSpring\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,27],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14591"}],"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=14591"}],"version-history":[{"count":6,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14591\/revisions"}],"predecessor-version":[{"id":14603,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/14591\/revisions\/14603"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}