{"id":6937,"date":"2024-11-14T15:30:59","date_gmt":"2024-11-14T07:30:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6937\/"},"modified":"2024-11-14T15:30:59","modified_gmt":"2024-11-14T07:30:59","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-queryrunner-%e8%8e%b7%e5%8f%96%e5%86%85%e9%83%a8%e7%b1%bb%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6937\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173011978598472.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>queryrunner \u4e2d\u5185\u90e8\u7c7b\u8fd4\u56de\u4e0d\u4e3a null \u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u5f00\u53d1\u8005\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\uff0c\u53ef\u80fd\u9047\u5230\u8fd9\u6837\u7684\u9700\u6c42\uff1a\u5728\u67e5\u8be2\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u83b7\u53d6\u67d0\u4e2a\u7c7b\u4e2d\u7684\u5185\u90e8\u7c7b\u6570\u636e\uff0c\u4f46\u4f7f\u7528 queryrunner \u65f6\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u4e2d\u7684\u5185\u90e8\u7c7b\u5374\u662f null\u3002\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f<\/p>\n<p>\u9488\u5bf9\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528 mybatis association \u6765\u5b9e\u73b0\u3002\u901a\u8fc7\u4f7f\u7528 association \u53ef\u4ee5\u5c06\u591a\u4e2a\u7c7b\u5173\u8054\u8d77\u6765\uff0c\u5f53\u67e5\u8be2\u67d0\u4e2a\u7c7b\u65f6\uff0c\u4f1a\u81ea\u52a8\u67e5\u8be2\u51fa\u5173\u8054\u7684\u7c7b\uff0c\u5e76\u5c06\u5176\u5c01\u88c5\u5728\u8fd4\u56de\u7ed3\u679c\u4e2d\u3002<\/p>\n<p>\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5728 customer \u7c7b\u4e2d\uff0c\u5b9a\u4e49\u5185\u90e8\u7c7b region\u3002<\/li>\n<li>\u5728 customer \u7c7b\u4e2d\uff0c\u4f7f\u7528 @joincolumn \u6ce8\u89e3\u5173\u8054 region\u3002<\/li>\n<li>\u5728 mybatis \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4e3a customer \u7c7b\u914d\u7f6e association\u3002<\/li>\n<\/ol>\n<p>\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/ Customer.java\npublic class Customer {\n    private Integer id;\n    private String name;\n    @JoinColumn(name = \"region_id\")\n    private Region region;\n    \/\/ ...\n}\n\n\/\/ Region.java\npublic class Region {\n    private Integer id;\n    private String name;\n    \/\/ ...\n}\n\n\/\/ mybatis \u914d\u7f6e\u6587\u4ef6\n&lt;resultMap id=\"CustomerResultMap\" type=\"Customer\"&gt;\n    &lt;id property=\"id\" column=\"id\" \/&gt;\n    &lt;result property=\"name\" column=\"name\" \/&gt;\n    &lt;association property=\"region\" javaType=\"Region\" column=\"region_id\" \/&gt;\n&lt;\/resultMap&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u6b64\u4e00\u6765\uff0c\u4f7f\u7528 queryrunner \u6267\u884c\u67e5\u8be2\u65f6\uff0c\u8fd4\u56de\u7684 customer \u5bf9\u8c61\u4e2d\u7684 region \u5c5e\u6027\u5c31\u4e0d\u4f1a\u4e3a null \u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\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>queryrunner \u4e2d\u5185\u90e8\u7c7b\u8fd4\u56de\u4e0d\u4e3a null \u7684\u65b9\u6cd5 \u5f00\u53d1\u8005\u5728\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\uff0c\u53ef\u80fd\u9047\u5230\u8fd9\u6837\u7684\u9700\u6c42\uff1a\u5728\u67e5\u8be2\u8fc7\u7a0b\u4e2d\uff0c\u9700\u8981\u83b7\u53d6\u67d0\u4e2a\u7c7b\u4e2d\u7684\u5185\u90e8\u7c7b\u6570\u636e\uff0c\u4f46\u4f7f\u7528 queryrunner \u65f6\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u4e2d\u7684\u5185\u90e8\u7c7b\u5374\u662f null\u3002\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f \u9488\u5bf9\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528 mybatis association \u6765\u5b9e\u73b0\u3002\u901a\u8fc7\u4f7f\u7528 association \u53ef\u4ee5\u5c06\u591a\u4e2a\u7c7b\u5173\u8054\u8d77\u6765\uff0c\u5f53\u67e5\u8be2\u67d0\u4e2a\u7c7b\u65f6\uff0c\u4f1a\u81ea\u52a8\u67e5\u8be2\u51fa\u5173\u8054\u7684\u7c7b\uff0c\u5e76\u5c06\u5176\u5c01\u88c5\u5728\u8fd4\u56de\u7ed3\u679c\u4e2d\u3002 \u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a \u5728 customer \u7c7b\u4e2d\uff0c\u5b9a\u4e49\u5185\u90e8\u7c7b region\u3002 \u5728 customer \u7c7b\u4e2d\uff0c\u4f7f\u7528 @joincolumn \u6ce8\u89e3\u5173\u8054 region\u3002 \u5728 mybatis \u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4e3a customer \u7c7b\u914d\u7f6e association\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a \/\/ Customer.java public class Customer { private Integer id; private String name; @JoinColumn(name = &#8220;region_id&#8221;) private Region region; \/\/ &#8230; } \/\/ Region.java [&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-6937","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6937","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=6937"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6937\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}