{"id":27359,"date":"2024-11-24T10:41:33","date_gmt":"2024-11-24T02:41:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27359\/"},"modified":"2024-11-24T10:41:33","modified_gmt":"2024-11-24T02:41:33","slug":"mysql-%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%bb%e9%94%ae%e8%87%aa%e5%a2%9e%e5%90%8e%e5%88%a0%e9%99%a4%e6%95%b0%e6%8d%ae%ef%bc%8cid-%e4%b8%8e%e9%a2%98%e7%9b%ae%e6%95%b0%e9%87%8f%e4%b8%8d%e4%b8%80%e8%87%b4-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27359\/","title":{"rendered":"Mysql \u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u540e\u5220\u9664\u6570\u636e\uff0cid \u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173123480318355.jpg\" class=\"aligncenter\" title=\"Mysql \u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u540e\u5220\u9664\u6570\u636e\uff0cid \u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"Mysql \u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u540e\u5220\u9664\u6570\u636e\uff0cid \u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u957f\u540e\u5220\u9664\u6570\u636e\uff0cid\u4e0e\u9898\u76ee\u4e2a\u6570\u4e0d\u4e00\u81f4\u7684\u5904\u7406<\/strong><\/p>\n<p>\u5728\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u62bd\u9898\u7684\u5c0f\u7a0b\u5e8f\u65f6\uff0c\u4f60\u4f7f\u7528mysql\u6570\u636e\u5e93\uff0c\u5c06id\u8bbe\u4e3a\u4e3b\u952e\u81ea\u589e\u957f\u3002\u7136\u800c\uff0c\u4f60\u9047\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5f53\u4f60\u5220\u9664\u6570\u636e\u65f6\uff0c\u6570\u636e\u5e93\u7684id\u4e0e\u9898\u76ee\u7684\u6570\u91cf\u4e0d\u4e00\u81f4\u4e86\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u67e5\u8be2\u6240\u6709\u9898\u76ee\uff0c\u7136\u540e\u5728\u968f\u673a\u9009\u62e9\u9898\u76ee\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>select * from questions;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8fd4\u56de\u6240\u6709\u9898\u76ee\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u9898\u76ee\uff1a<\/p>\n<pre>Random random = new Random();\nint randomId = random.nextInt(questions.size());\nQuestion question = questions.get(randomId);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2arandom\u5bf9\u8c61\uff0c\u5e76\u751f\u6210\u4e00\u4e2a0\u5230questions.size()-1\u4e4b\u95f4\u7684\u968f\u673a\u6570\u3002\u7136\u540e\uff0c\u5b83\u5c06\u4f7f\u7528\u8fd9\u4e2a\u968f\u673a\u6570\u6765\u83b7\u53d6\u9898\u76ee\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u9898\u76ee\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u5220\u9664\u6570\u636e\u540e\u4ecd\u7136\u4ece\u6570\u636e\u5e93\u4e2d\u968f\u673a\u9009\u62e9\u9898\u76ee\uff0c\u800c\u4e0d\u4f1a\u51fa\u73b0id\u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMysql \u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u540e\u5220\u9664\u6570\u636e\uff0cid \u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u957f\u540e\u5220\u9664\u6570\u636e\uff0cid\u4e0e\u9898\u76ee\u4e2a\u6570\u4e0d\u4e00\u81f4\u7684\u5904\u7406 \u5728\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u62bd\u9898\u7684\u5c0f\u7a0b\u5e8f\u65f6\uff0c\u4f60\u4f7f\u7528mysql\u6570\u636e\u5e93\uff0c\u5c06id\u8bbe\u4e3a\u4e3b\u952e\u81ea\u589e\u957f\u3002\u7136\u800c\uff0c\u4f60\u9047\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5f53\u4f60\u5220\u9664\u6570\u636e\u65f6\uff0c\u6570\u636e\u5e93\u7684id\u4e0e\u9898\u76ee\u7684\u6570\u91cf\u4e0d\u4e00\u81f4\u4e86\u3002 \u89e3\u51b3\u65b9\u6cd5 \u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u67e5\u8be2\u6240\u6709\u9898\u76ee\uff0c\u7136\u540e\u5728\u968f\u673a\u9009\u62e9\u9898\u76ee\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a select * from questions; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u6bb5\u4ee3\u7801\u5c06\u8fd4\u56de\u6240\u6709\u9898\u76ee\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u9898\u76ee\uff1a Random random = new Random(); int randomId = random.nextInt(questions.size()); Question question = questions.get(randomId); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u6bb5\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2arandom\u5bf9\u8c61\uff0c\u5e76\u751f\u6210\u4e00\u4e2a0\u5230questions.size()-1\u4e4b\u95f4\u7684\u968f\u673a\u6570\u3002\u7136\u540e\uff0c\u5b83\u5c06\u4f7f\u7528\u8fd9\u4e2a\u968f\u673a\u6570\u6765\u83b7\u53d6\u9898\u76ee\u5217\u8868\u4e2d\u7684\u4e00\u4e2a\u9898\u76ee\u3002 \u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u5220\u9664\u6570\u636e\u540e\u4ecd\u7136\u4ece\u6570\u636e\u5e93\u4e2d\u968f\u673a\u9009\u62e9\u9898\u76ee\uff0c\u800c\u4e0d\u4f1a\u51fa\u73b0id\u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u7684\u95ee\u9898\u3002 \u4ee5\u4e0a\u5c31\u662fMysql \u6570\u636e\u5e93\u4e3b\u952e\u81ea\u589e\u540e\u5220\u9664\u6570\u636e\uff0cid \u4e0e\u9898\u76ee\u6570\u91cf\u4e0d\u4e00\u81f4\u600e\u4e48\u529e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-27359","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27359","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=27359"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27359\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}