{"id":44575,"date":"2024-12-01T12:54:36","date_gmt":"2024-12-01T04:54:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/44575\/"},"modified":"2024-12-01T12:54:36","modified_gmt":"2024-12-01T04:54:36","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/44575\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f<\/h1>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730120443671f8afbeb1f0.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>\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>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 QueryRunner \u83b7\u53d6\u5185\u90e8\u7c7b\u6570\u636e\uff1f \u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~ 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; \/\/ [&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-44575","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44575","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=44575"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44575\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=44575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=44575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=44575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}