{"id":7021,"date":"2024-11-14T14:33:12","date_gmt":"2024-11-14T06:33:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7021\/"},"modified":"2024-11-14T14:33:12","modified_gmt":"2024-11-14T06:33:12","slug":"springbootmybatismysql-%e6%89%b9%e9%87%8f%e6%96%b0%e5%a2%9e%e6%95%b0%e6%8d%ae%e6%97%b6%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8doom%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7021\/","title":{"rendered":"SpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173028611580030.jpg\" class=\"aligncenter\" title=\"SpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\uff1f\u63d2\u56fe\" alt=\"SpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>springboot+mybatis+\u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\uff0c\u907f\u514d\u6570\u636e\u8fc7\u5927\u5f15\u53d1oom<\/h2>\n<p>\u5728\u6279\u91cf\u65b0\u589e\u6570\u636e\u5230\u6570\u636e\u5e93\u65f6\uff0c\u7531\u4e8e\u6570\u636e\u91cf\u4e0d\u786e\u5b9a\uff0c\u53ef\u80fd\u5bfc\u81f4\u51fa\u73b0oom\uff08\u5185\u5b58\u6ea2\u51fa\uff09\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u907f\u514d\u8fd9\u79cd\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848\uff1a\u5206\u6279\u4fdd\u5b58<\/h3>\n<p><strong>1. \u4ee3\u7801\u4f18\u5316<\/strong><\/p>\n<p>\u63d0\u4f9b\u7684\u4ee3\u7801\u5728\u5904\u7406\u6700\u540e\u4e00\u6bb5\u6570\u636e\u65f6\uff0c\u9700\u8981\u5355\u72ec\u5904\u7406\u3002\u53ef\u4ee5\u5bf9\u4ee3\u7801\u8fdb\u884c\u5982\u4e0b\u4f18\u5316\uff1a<\/p>\n<pre>public void insert(list&lt;user&gt; list) {\n    int count = 10000; \/\/ \u6bcf\u6b21\u5904\u7406\u6570\u636e\u91cf\n    int pagesize = list.size() % count == 0 ? list.size() \/ count : list.size() \/ count + 1;\n    for(int i=0; i&lt;pagesize; i++){\n        list&lt;integer&gt; list1 = list.sublist(i * count, (i + 1) * count &lt;= list.size() ? (i + 1) * count : list.size());\n        usermapper.insert(list1); \/\/ \u6bcf\u6b21\u4f20count\u6570\u91cf\u7684\u6570\u636e\u5230mapper\u65b9\u6cd5\u91cc\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u66f4\u4f18\u65b9\u6cd5\uff1a\u6279\u91cf\u66f4\u65b0sql<\/strong><\/p>\n<p>\u9664\u4e86\u5206\u6279\u4fdd\u5b58\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u6279\u91cf\u66f4\u65b0sql\u6765\u66f4\u6709\u6548\u5730\u63d2\u5165\u6570\u636e\u3002 <\/p>\n<pre>INSERT INTO user (name, age) VALUES\n(?, ?),\n(?, ?),\n...\n(?, ?);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u5c06\u591a\u6761insert\u8bed\u53e5\u7ec4\u5408\u6210\u5355\u4e2a\u6279\u91cf\u8bed\u53e5\uff0c\u53ef\u4ee5\u663e\u7740\u51cf\u5c11\u6570\u636e\u5e93\u4ea4\u4e92\u6b21\u6570\uff0c\u4ece\u800c\u63d0\u9ad8\u6027\u80fd\u3002 <\/p>\n<p>\u4e0d\u8981\u8fc7\u5ea6\u89c4\u8303\u6570\u636e\u91cf\u7684\u5927\u5c0f\uff0c\u5e94\u8be5\u6839\u636e\u5b9e\u9645\u4e1a\u52a1\u60c5\u51b5\u548c\u7cfb\u7edf\u8d44\u6e90\u60c5\u51b5\u6765\u51b3\u5b9a\u3002\u540c\u65f6\uff0c\u4e5f\u8981\u6ce8\u610f\u76d1\u63a7\u7cfb\u7edf\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\uff0c\u907f\u514d\u8d85\u51fa\u9650\u5236\u3002 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSpringBoot+MyBatis+MySQL \u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\u5982\u4f55\u907f\u514dOOM\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>springboot+mybatis+\u6279\u91cf\u65b0\u589e\u6570\u636e\u65f6\uff0c\u907f\u514d\u6570\u636e\u8fc7\u5927\u5f15\u53d1oom \u5728\u6279\u91cf\u65b0\u589e\u6570\u636e\u5230\u6570\u636e\u5e93\u65f6\uff0c\u7531\u4e8e\u6570\u636e\u91cf\u4e0d\u786e\u5b9a\uff0c\u53ef\u80fd\u5bfc\u81f4\u51fa\u73b0oom\uff08\u5185\u5b58\u6ea2\u51fa\uff09\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u907f\u514d\u8fd9\u79cd\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\uff1a \u89e3\u51b3\u65b9\u6848\uff1a\u5206\u6279\u4fdd\u5b58 1. \u4ee3\u7801\u4f18\u5316 \u63d0\u4f9b\u7684\u4ee3\u7801\u5728\u5904\u7406\u6700\u540e\u4e00\u6bb5\u6570\u636e\u65f6\uff0c\u9700\u8981\u5355\u72ec\u5904\u7406\u3002\u53ef\u4ee5\u5bf9\u4ee3\u7801\u8fdb\u884c\u5982\u4e0b\u4f18\u5316\uff1a public void insert(list&lt;user&gt; list) { int count = 10000; \/\/ \u6bcf\u6b21\u5904\u7406\u6570\u636e\u91cf int pagesize = list.size() % count == 0 ? list.size() \/ count : list.size() \/ count + 1; for(int i=0; i&lt;pagesize; i++){ list&lt;integer&gt; list1 = list.sublist(i * count, (i + 1) * count &lt;= list.size() ? (i + [&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-7021","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7021","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=7021"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7021\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}