{"id":6875,"date":"2024-11-14T15:38:02","date_gmt":"2024-11-14T07:38:02","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6875\/"},"modified":"2024-11-14T15:38:02","modified_gmt":"2024-11-14T07:38:02","slug":"springmvc-%e8%bf%9e%e6%8e%a5-mysql-%e9%81%87%e5%88%b0%e8%bf%9e%e6%8e%a5%e9%94%99%e8%af%af%ef%bc%8c%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e8%af%a6%e7%bb%86%e6%8a%a5%e9%94%99%e4%bf%a1%e6%81%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6875\/","title":{"rendered":"SpringMVC \u8fde\u63a5 MySQL \u9047\u5230\u8fde\u63a5\u9519\u8bef\uff0c\u5982\u4f55\u83b7\u53d6\u8be6\u7ec6\u62a5\u9519\u4fe1\u606f\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173000381788074.jpg\" class=\"aligncenter\" title=\"SpringMVC \u8fde\u63a5 MySQL \u9047\u5230\u8fde\u63a5\u9519\u8bef\uff0c\u5982\u4f55\u83b7\u53d6\u8be6\u7ec6\u62a5\u9519\u4fe1\u606f\uff1f\u63d2\u56fe\" alt=\"SpringMVC \u8fde\u63a5 MySQL \u9047\u5230\u8fde\u63a5\u9519\u8bef\uff0c\u5982\u4f55\u83b7\u53d6\u8be6\u7ec6\u62a5\u9519\u4fe1\u606f\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>springmvc \u8fde\u63a5  \u9047\u5230\u7684\u5e38\u89c1\u95ee\u9898<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 springmvc \u6846\u67b6\u8fde\u63a5 mysql \u6570\u636e\u5e93\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u95ee\u9898\u3002\u5176\u4e2d\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u6545\u610f\u5c06 mysql \u5199\u9519\u6210 mysq\u3002<\/p>\n<p><strong>\u95ee\u9898\u8868\u73b0<\/strong><\/p>\n<p>\u5f53\u51fa\u73b0\u6b64\u95ee\u9898\u65f6\uff0c \u542f\u52a8\u4fe1\u606f\u4f1a\u4e00\u76f4\u505c\u7559\u5728\u8fde\u63a5\u6570\u636e\u5e93\u7684\u6b65\u9aa4\u3002\u4e0d\u4f1a\u8f93\u51fa\u6709\u5173\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982\u6570\u636e\u5e93\u4e0d\u5b58\u5728\u3002<\/p>\n<p><strong>\u89e3\u51b3\u601d\u8def<\/strong><\/p>\n<p>\u4e00\u79cd\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u601d\u8def\u662f\u8bbe\u7f6e\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u3002\u5982\u679c\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u65e0\u6cd5\u83b7\u53d6\u5230\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5b83\u5c06\u8f93\u51fa\u6709\u5173\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982\u6570\u636e\u5e93\u4e0d\u5b58\u5728\u3002<\/p>\n<p><strong>\u5177\u4f53\u5b9e\u73b0<\/strong><\/p>\n<pre>&lt;bean id=\"dataSource\" class=\"org.apache.commons.dbcp.BasicDataSource\" destroy-method=\"close\"&gt;\n    &lt;property name=\"driverClassName\" value=\"com.mysql.jdbc.Driver\" \/&gt;\n    &lt;property name=\"url\" value=\"jdbc:mysql:\/\/localhost:3306\/test\" \/&gt;\n    &lt;property name=\"username\" value=\"root\" \/&gt;\n    &lt;property name=\"password\" value=\"password\" \/&gt;\n    &lt;property name=\"maxActive\" value=\"10\" \/&gt;\n    &lt;property name=\"maxIdle\" value=\"5\" \/&gt;\n    &lt;property name=\"minIdle\" value=\"2\" \/&gt;\n    &lt;!-- \u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u6beb\u79d2 --&gt;\n    &lt;property name=\"maxWait\" value=\"5000\" \/&gt;\n&lt;\/bean&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u8bbe\u7f6e maxwt \u5c5e\u6027\uff0c\u60a8\u53ef\u4ee5\u6307\u5b9a\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u3002\u5982\u679c\u5728 5 \u79d2\u5185\u65e0\u6cd5\u83b7\u53d6\u5230\u8fde\u63a5\uff0c\u5b83\u5c06\u8f93\u51fa\u6709\u5173\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5<\/strong><\/p>\n<p>\u9664\u4e86\u8bbe\u7f6e\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u4e4b\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u83b7\u53d6\u6709\u5173\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 init-method \u5c5e\u6027\u6216 @postconstruct \u6ce8\u91ca\u3002<\/li>\n<li>\u5b9e\u73b0 initializingbean \u63a5\u53e3\u3002<\/li>\n<li>\u4f7f\u7528\u963f\u91cc\u5df4\u5df4\u7684 druid \u6570\u636e\u6e90\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fSpringMVC \u8fde\u63a5 MySQL \u9047\u5230\u8fde\u63a5\u9519\u8bef\uff0c\u5982\u4f55\u83b7\u53d6\u8be6\u7ec6\u62a5\u9519\u4fe1\u606f\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>springmvc \u8fde\u63a5 \u9047\u5230\u7684\u5e38\u89c1\u95ee\u9898 \u5728\u4f7f\u7528 springmvc \u6846\u67b6\u8fde\u63a5 mysql \u6570\u636e\u5e93\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u95ee\u9898\u3002\u5176\u4e2d\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u6545\u610f\u5c06 mysql \u5199\u9519\u6210 mysq\u3002 \u95ee\u9898\u8868\u73b0 \u5f53\u51fa\u73b0\u6b64\u95ee\u9898\u65f6\uff0c \u542f\u52a8\u4fe1\u606f\u4f1a\u4e00\u76f4\u505c\u7559\u5728\u8fde\u63a5\u6570\u636e\u5e93\u7684\u6b65\u9aa4\u3002\u4e0d\u4f1a\u8f93\u51fa\u6709\u5173\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982\u6570\u636e\u5e93\u4e0d\u5b58\u5728\u3002 \u89e3\u51b3\u601d\u8def \u4e00\u79cd\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u601d\u8def\u662f\u8bbe\u7f6e\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\u3002\u5982\u679c\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u65e0\u6cd5\u83b7\u53d6\u5230\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u5b83\u5c06\u8f93\u51fa\u6709\u5173\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u4f8b\u5982\u6570\u636e\u5e93\u4e0d\u5b58\u5728\u3002 \u5177\u4f53\u5b9e\u73b0 &lt;bean id=&#8221;dataSource&#8221; class=&#8221;org.apache.commons.dbcp.BasicDataSource&#8221; destroy-method=&#8221;close&#8221;&gt; &lt;property name=&#8221;driverClassName&#8221; value=&#8221;com.mysql.jdbc.Driver&#8221; \/&gt; &lt;property name=&#8221;url&#8221; value=&#8221;jdbc:mysql:\/\/localhost:3306\/test&#8221; \/&gt; &lt;property name=&#8221;username&#8221; value=&#8221;root&#8221; \/&gt; &lt;property name=&#8221;password&#8221; value=&#8221;password&#8221; \/&gt; &lt;property name=&#8221;maxActive&#8221; value=&#8221;10&#8243; \/&gt; &lt;property name=&#8221;maxIdle&#8221; value=&#8221;5&#8243; \/&gt; &lt;property name=&#8221;minIdle&#8221; value=&#8221;2&#8243; \/&gt; &lt;!&#8211; \u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff0c\u5355\u4f4d\u4e3a\u6beb\u79d2 &#8211;&gt; &lt;property name=&#8221;maxWait&#8221; value=&#8221;5000&#8243; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6875","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6875"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6875\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}