{"id":50194,"date":"2025-07-30T21:52:09","date_gmt":"2025-07-30T13:52:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/50194.html"},"modified":"2025-07-30T21:52:09","modified_gmt":"2025-07-30T13:52:09","slug":"mybatis-resultmap-%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a%e6%9e%84%e5%bb%ba%e9%ab%98%e6%95%88%e7%9a%84%e5%85%b3%e8%81%94%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/50194.html","title":{"rendered":"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2"},"content":{"rendered":"<h3>\u5728 Java \u6301\u4e45\u5c42\u6846\u67b6 MyBatis \u4e2d&#xff0c;resultMap \u662f\u4e00\u4e2a\u6781\u5176\u5f3a\u5927\u7684\u5de5\u5177&#xff0c;\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u7cbe\u786e\u5730\u63a7\u5236 SQL \u67e5\u8be2\u7ed3\u679c\u5230 Java \u5bf9\u8c61\u7684\u6620\u5c04\u8fc7\u7a0b\u3002\u5c24\u5176\u662f\u5728\u5904\u7406\u590d\u6742\u7684\u5173\u8054\u67e5\u8be2&#xff08;\u5982\u4e00\u5bf9\u4e00\u3001\u4e00\u5bf9\u591a&#xff09;\u65f6&#xff0c;resultMap \u7684\u4f5c\u7528\u66f4\u662f\u4e0d\u53ef\u66ff\u4ee3\u3002\u672c\u6587\u5c06\u5e26\u4f60\u6df1\u5165\u7406\u89e3 resultMap \u7684\u6838\u5fc3\u6982\u5ff5\u3001\u4e3b\u8981\u5143\u7d20&#xff0c;\u5e76\u901a\u8fc7\u8be6\u7ec6\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u4f7f\u7528\u5b83\u6765\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2\u3002<\/h3>\n<\/p>\n<h4>\u4e00\u3001\u4e3a\u4ec0\u4e48\u4f60\u9700\u8981 resultMap&#xff1f;<\/h4>\n<\/p>\n<p>MyBatis \u7684\u81ea\u52a8\u6620\u5c04\u529f\u80fd\u5728\u7b80\u5355\u7684\u67e5\u8be2\u4e2d\u8868\u73b0\u51fa\u8272&#xff0c;\u4f46\u5f53\u9047\u5230\u4ee5\u4e0b\u573a\u666f\u65f6&#xff0c;resultMap \u5c31\u53d8\u5f97\u5fc5\u4e0d\u53ef\u5c11&#xff1a;<\/p>\n<li>\n<p>\u6570\u636e\u5e93\u5217\u540d\u4e0e Java \u5c5e\u6027\u540d\u4e0d\u4e00\u81f4&#xff1a; \u6570\u636e\u5e93\u4e2d\u901a\u5e38\u4f7f\u7528 snake_case&#xff08;\u5982 user_name&#xff09;&#xff0c;\u800c Java \u4e2d\u5e38\u7528 camelCase&#xff08;\u5982 userName&#xff09;\u3002resultMap \u53ef\u4ee5\u663e\u5f0f\u5730\u5efa\u7acb\u8fd9\u79cd\u6620\u5c04\u5173\u7cfb\u3002<\/p>\n<\/li>\n<li>\n<p>\u590d\u6742\u7684\u6570\u636e\u7c7b\u578b\u8f6c\u6362&#xff1a; \u4f8b\u5982&#xff0c;\u5c06\u6570\u636e\u5e93\u7684 TINYINT \u8f6c\u6362\u4e3a Java \u7684 Boolean&#xff0c;\u6216\u81ea\u5b9a\u4e49\u7c7b\u578b\u5904\u7406\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>\u6784\u5efa\u590d\u6742\u7684\u5bf9\u8c61\u56fe&#xff1a; \u8fd9\u662f resultMap \u6700\u91cd\u8981\u7684\u5e94\u7528\u573a\u666f\u3002\u5f53\u4f60\u7684\u4e00\u4e2a Java \u5bf9\u8c61\u5305\u542b\u5176\u4ed6\u5bf9\u8c61&#xff08;\u4e00\u5bf9\u4e00&#xff09;\u6216\u5bf9\u8c61\u96c6\u5408&#xff08;\u4e00\u5bf9\u591a&#xff09;\u65f6&#xff0c;resultMap \u80fd\u591f\u5e2e\u52a9\u4f60\u5c06\u6241\u5e73\u5316\u7684 SQL \u7ed3\u679c\u96c6\u6620\u5c04\u4e3a\u5bcc\u6709\u5c42\u6b21\u611f\u7684 Java \u5bf9\u8c61\u7ed3\u6784\u3002<\/p>\n<\/li>\n<li>\n<p>\u63a7\u5236\u52a0\u8f7d\u7b56\u7565&#xff1a; \u53ef\u4ee5\u914d\u7f6e\u5173\u8054\u5bf9\u8c61\u662f\u5373\u65f6\u52a0\u8f7d&#xff08;Eager Loading&#xff09;\u8fd8\u662f\u61d2\u52a0\u8f7d&#xff08;Lazy Loading&#xff09;\u3002<\/p>\n<\/li>\n<h4>\u4e8c\u3001resultMap \u7684\u6838\u5fc3\u5143\u7d20<\/h4>\n<\/p>\n<p>\u4e00\u4e2a resultMap \u901a\u5e38\u7531\u4ee5\u4e0b\u4e3b\u8981\u5b50\u5143\u7d20\u6784\u6210&#xff1a;<\/p>\n<ul>\n<li>\n<p>&lt;id&gt;&#xff1a;\u4e3b\u952e\u6620\u5c04<\/p>\n<ul>\n<li>\n<p>\u7528\u4e8e\u6620\u5c04\u6570\u636e\u5e93\u8868\u7684\u4e3b\u952e\u5217\u3002<\/p>\n<\/li>\n<li>\n<p>column&#xff1a;\u6570\u636e\u5e93\u4e2d\u7684\u5217\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>property&#xff1a;Java \u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>jdbcType&#xff1a;JDBC \u7c7b\u578b&#xff08;\u53ef\u9009&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>javaType&#xff1a;Java \u7c7b\u578b&#xff08;\u53ef\u9009&#xff0c;MyBatis \u5927\u591a\u53ef\u63a8\u65ad&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u91cd\u8981\u6027&#xff1a; MyBatis \u4f9d\u636e &lt;id&gt; \u6807\u7b7e\u8bc6\u522b\u7ed3\u679c\u96c6\u4e2d\u884c\u7684\u552f\u4e00\u6027&#xff0c;\u5c24\u5176\u5728\u5904\u7406\u4e00\u5bf9\u591a\u5173\u7cfb\u65f6&#xff0c;\u5b83\u80fd\u5e2e\u52a9 MyBatis \u6b63\u786e\u805a\u5408\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>&lt;result&gt;&#xff1a;\u666e\u901a\u5217\u6620\u5c04<\/p>\n<ul>\n<li>\n<p>\u7528\u4e8e\u6620\u5c04\u6570\u636e\u5e93\u8868\u7684\u975e\u4e3b\u952e\u5217\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c5e\u6027\u4e0e &lt;id&gt; \u7c7b\u4f3c\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>&lt;association&gt;&#xff1a;\u4e00\u5bf9\u4e00&#xff08;One-to-One&#xff09;\u5173\u8054\u6620\u5c04<\/p>\n<ul>\n<li>\n<p>\u7528\u4e8e\u6620\u5c04 Java \u5bf9\u8c61\u4e2d\u5d4c\u5957\u7684\u5355\u4e2a\u5bf9\u8c61\u5c5e\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>property&#xff1a;Java \u5bf9\u8c61\u4e2d\u8868\u793a\u5173\u8054\u5bf9\u8c61\u7684\u5c5e\u6027\u540d&#xff08;\u4f8b\u5982 User \u5bf9\u8c61\u4e2d\u7684 Address address&#xff0c;property \u5c31\u662f address&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>javaType&#xff1a;\u5173\u8054\u5bf9\u8c61\u7684 Java \u7c7b\u578b&#xff08;\u4f8b\u5982 com.example.Address&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5d4c\u5957\u7ed3\u679c&#xff08;\u5373\u65f6\u52a0\u8f7d&#xff09;\u65b9\u5f0f&#xff1a; \u5185\u90e8\u5305\u542b &lt;id&gt; \u548c &lt;result&gt;&#xff0c;\u76f4\u63a5\u6620\u5c04 JOIN \u67e5\u8be2\u7684\u7ed3\u679c\u96c6\u4e2d\u7684\u5173\u8054\u5217\u3002<\/p>\n<\/li>\n<li>\n<p>\u5d4c\u5957\u67e5\u8be2&#xff08;\u61d2\u52a0\u8f7d&#xff09;\u65b9\u5f0f&#xff1a; column&#xff08;\u4f20\u9012\u7ed9\u5b50\u67e5\u8be2\u7684\u53c2\u6570&#xff09;\u548c select&#xff08;\u5b50\u67e5\u8be2\u7684\u8bed\u53e5 ID&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>&lt;collection&gt;&#xff1a;\u4e00\u5bf9\u591a&#xff08;One-to-Many&#xff09;\u5173\u8054\u6620\u5c04<\/p>\n<ul>\n<li>\n<p>\u7528\u4e8e\u6620\u5c04 Java \u5bf9\u8c61\u4e2d\u5d4c\u5957\u7684\u5bf9\u8c61\u96c6\u5408\u5c5e\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>property&#xff1a;Java \u5bf9\u8c61\u4e2d\u8868\u793a\u96c6\u5408\u7684\u5c5e\u6027\u540d&#xff08;\u4f8b\u5982 User \u5bf9\u8c61\u4e2d\u7684 List&lt;Order&gt; orders&#xff0c;property \u5c31\u662f orders&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>ofType&#xff1a;\u8fd9\u662f\u5173\u952e&#xff01; \u6307\u5b9a\u96c6\u5408\u4e2d\u5143\u7d20\u7684 Java \u7c7b\u578b&#xff08;\u4f8b\u5982 com.example.Order&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5176\u4ed6\u5c5e\u6027\u4e0e &lt;association&gt; \u7c7b\u4f3c&#xff0c;\u4e5f\u5206\u4e3a\u5d4c\u5957\u7ed3\u679c\u548c\u5d4c\u5957\u67e5\u8be2\u4e24\u79cd\u65b9\u5f0f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u4e09\u3001\u5173\u8054\u67e5\u8be2\u7b56\u7565\u8be6\u89e3<\/h4>\n<\/p>\n<p>MyBatis \u4e3b\u8981\u652f\u6301\u4e24\u79cd\u5173\u8054\u67e5\u8be2\u7b56\u7565&#xff1a;<\/p>\n<\/p>\n<h5>3.1 \u5d4c\u5957\u7ed3\u679c&#xff08;Nested Results \/ Eager Loading \/ \u5373\u65f6\u52a0\u8f7d&#xff09;<\/h5>\n<\/p>\n<ul>\n<li>\n<p>\u539f\u7406&#xff1a; \u53ea\u6267\u884c\u4e00\u6b21 SQL \u67e5\u8be2&#xff0c;\u8be5\u67e5\u8be2\u5305\u542b JOIN \u8bed\u53e5&#xff0c;\u4e00\u6b21\u6027\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u6240\u6709\u76f8\u5173\u6570\u636e\u3002MyBatis \u968f\u540e\u4f1a\u6839\u636e resultMap \u7684\u5b9a\u4e49&#xff0c;\u5c06\u7ed3\u679c\u96c6\u4e2d\u7684\u6241\u5e73\u6570\u636e\u6620\u5c04\u5230\u4e3b\u5bf9\u8c61\u53ca\u5176\u5d4c\u5957\u7684\u5173\u8054\u5bf9\u8c61\u548c\u96c6\u5408\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9ad8\u6548&#xff1a; \u51cf\u5c11\u6570\u636e\u5e93\u7684\u5f80\u8fd4\u6b21\u6570&#xff08;\u53ea\u9700\u4e00\u6b21&#xff09;&#xff0c;\u964d\u4f4e\u7f51\u7edc\u5ef6\u8fdf\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b80\u5355&#xff1a; \u9002\u7528\u4e8e\u5927\u591a\u6570\u5173\u8054\u67e5\u8be2\u573a\u666f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5bf9\u4e8e\u4e00\u5bf9\u591a\u5173\u7cfb&#xff0c;\u4e3b\u8868\u7684\u6570\u636e\u53ef\u80fd\u4f1a\u5728\u7ed3\u679c\u96c6\u4e2d\u91cd\u590d\u51fa\u73b0&#xff08;MyBatis \u4f1a\u81ea\u52a8\u53bb\u91cd\u5e76\u805a\u5408\u5230\u96c6\u5408\u4e2d&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u5173\u8054\u6570\u636e\u91cf\u975e\u5e38\u5927&#xff0c;\u4e00\u6b21\u6027\u52a0\u8f7d\u6240\u6709\u6570\u636e\u53ef\u80fd\u4f1a\u6d88\u8017\u66f4\u591a\u5185\u5b58\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9002\u7528\u573a\u666f&#xff1a; \u5173\u8054\u6570\u636e\u901a\u5e38\u4f1a\u88ab\u4e00\u8d77\u67e5\u8be2&#xff0c;\u6216\u8005\u6570\u636e\u91cf\u76f8\u5bf9\u8f83\u5c0f\u3002<\/p>\n<\/li>\n<\/ul>\n<h5>3.2 \u5d4c\u5957\u67e5\u8be2&#xff08;Nested Selects \/ Lazy Loading \/ \u61d2\u52a0\u8f7d&#xff09;<\/h5>\n<\/p>\n<ul>\n<li>\n<p>\u539f\u7406&#xff1a; \u5206\u591a\u6b21\u6267\u884c SQL \u67e5\u8be2\u3002\u9996\u5148\u6267\u884c\u4e00\u4e2a\u4e3b\u67e5\u8be2\u6765\u52a0\u8f7d\u4e3b\u5bf9\u8c61&#xff0c;\u7136\u540e&#xff0c;\u5f53\u4ee3\u7801\u5b9e\u9645\u8bbf\u95ee\u4e3b\u5bf9\u8c61\u4e2d\u7684\u5173\u8054\u5c5e\u6027\u65f6&#xff08;\u6216\u8005\u6839\u636e\u914d\u7f6e&#xff09;&#xff0c;MyBatis \u624d\u4f1a\u6267\u884c\u989d\u5916\u7684 SQL \u67e5\u8be2\u6765\u52a0\u8f7d\u5173\u8054\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6309\u9700\u52a0\u8f7d&#xff1a; \u907f\u514d\u52a0\u8f7d\u4e0d\u5fc5\u8981\u7684\u6570\u636e&#xff0c;\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b80\u5316 SQL&#xff1a; \u6bcf\u4e2a\u67e5\u8be2\u53ef\u4ee5\u4fdd\u6301\u76f8\u5bf9\u7b80\u5355\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>N&#043;1 \u67e5\u8be2\u95ee\u9898&#xff1a; \u5982\u679c\u4f60\u67e5\u8be2 N \u4e2a\u4e3b\u5bf9\u8c61&#xff0c;\u5e76\u4e14\u6bcf\u4e2a\u4e3b\u5bf9\u8c61\u90fd\u9700\u8981\u52a0\u8f7d\u5173\u8054\u5bf9\u8c61&#xff0c;\u90a3\u4e48\u53ef\u80fd\u4f1a\u5bfc\u81f4 N&#043;1 \u6b21\u6570\u636e\u5e93\u67e5\u8be2&#xff08;1\u6b21\u4e3b\u67e5\u8be2 &#043; N\u6b21\u5173\u8054\u67e5\u8be2&#xff09;&#xff0c;\u6027\u80fd\u53ef\u80fd\u4e0b\u964d\u3002<\/p>\n<\/li>\n<li>\n<p>\u589e\u52a0\u6570\u636e\u5e93\u5f80\u8fd4\u6b21\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u9002\u7528\u573a\u666f&#xff1a; \u5173\u8054\u6570\u636e\u91cf\u53ef\u80fd\u975e\u5e38\u5927&#xff0c;\u6216\u8005\u5173\u8054\u6570\u636e\u4e0d\u7ecf\u5e38\u88ab\u8bbf\u95ee\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b&#xff0c;\u63a8\u8350\u4f7f\u7528 \u5d4c\u5957\u7ed3\u679c&#xff08;\u5373\u65f6\u52a0\u8f7d&#xff09; \u6765\u907f\u514d N&#043;1 \u67e5\u8be2\u95ee\u9898\u3002<\/p>\n<\/p>\n<h4>\u56db\u3001\u5b9e\u8df5\u6848\u4f8b&#xff1a;\u7528\u6237\u3001\u521b\u5efa\u4eba\u3001\u4fee\u6539\u4eba\u4e0e\u89d2\u8272\u5217\u8868<\/h4>\n<\/p>\n<p>\u6211\u4eec\u4ee5\u4e00\u4e2a\u5178\u578b\u7684 TUser \u7c7b\u4e3a\u4f8b&#xff0c;\u5b83\u5305\u542b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e00\u5bf9\u4e00\u5173\u8054&#xff1a; createByDO (\u521b\u5efa\u4eba&#xff0c;\u4e5f\u662f TUser \u7c7b\u578b), editByDO (\u4fee\u6539\u4eba&#xff0c;\u4e5f\u662f TUser \u7c7b\u578b)\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e00\u5bf9\u591a\u5173\u8054&#xff1a; tRoleList (\u7528\u6237\u89d2\u8272\u5217\u8868&#xff0c;TRole \u7c7b\u578b)\u3002<\/p>\n<\/li>\n<\/ul>\n<p>Java Bean \u7ed3\u6784&#xff1a;<\/p>\n<p>Java<\/p>\n<\/p>\n<p>\/\/ TUser.java<br \/>\npublic class TUser {<br \/>\n    private Integer id;<br \/>\n    private String loginAct;<br \/>\n    private String name; \/\/ \u7528\u6237\u59d3\u540d<br \/>\n    \/\/ &#8230; \u5176\u4ed6\u57fa\u672c\u5c5e\u6027 &#8230;<\/p>\n<p>    \/\/ \u5173\u8054\u5c5e\u6027&#xff1a;\u521b\u5efa\u4eba (\u4e00\u5bf9\u4e00)<br \/>\n    private TUser createByDO;<br \/>\n    \/\/ \u5173\u8054\u5c5e\u6027&#xff1a;\u4fee\u6539\u4eba (\u4e00\u5bf9\u4e00)<br \/>\n    private TUser editByDO;<br \/>\n    \/\/ \u5173\u8054\u5c5e\u6027&#xff1a;\u89d2\u8272\u5217\u8868 (\u4e00\u5bf9\u591a)<br \/>\n    private List&lt;TRole&gt; tRoleList;<\/p>\n<p>    \/\/ Getter\/Setter &#8230;<br \/>\n}<\/p>\n<p>\/\/ TRole.java<br \/>\npublic class TRole {<br \/>\n    private Integer id;<br \/>\n    private String role; \/\/ \u89d2\u8272\u82f1\u6587\u6807\u8bc6<br \/>\n    private String name; \/\/ \u89d2\u8272\u540d\u79f0<br \/>\n    \/\/ Getter\/Setter &#8230;<br \/>\n}<\/p>\n<p>\u6570\u636e\u5e93\u8868\u7ed3\u6784&#xff08;\u7b80\u5316&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>t_user: id, login_act, name, create_by, edit_by<\/p>\n<\/li>\n<li>\n<p>t_role: id, role, name<\/p>\n<\/li>\n<li>\n<p>t_user_role: user_id, role_id (\u7528\u6237-\u89d2\u8272\u4e2d\u95f4\u8868)<\/p>\n<\/li>\n<\/ul>\n<h5>4.1 \u5d4c\u5957\u7ed3\u679c&#xff08;\u5373\u65f6\u52a0\u8f7d&#xff09;\u5b9e\u73b0<\/h5>\n<\/p>\n<p>\u76ee\u6807&#xff1a; \u901a\u8fc7\u4e00\u6b21 SQL \u67e5\u8be2&#xff0c;\u83b7\u53d6\u7528\u6237\u6240\u6709\u4fe1\u606f&#xff0c;\u5305\u62ec\u521b\u5efa\u4eba\u3001\u4fee\u6539\u4eba\u7684\u59d3\u540d\/\u8d26\u53f7&#xff0c;\u4ee5\u53ca\u6240\u6709\u5173\u8054\u7684\u89d2\u8272\u4fe1\u606f\u3002<\/p>\n<p>\u6b65\u9aa4 1&#xff1a;\u5b9a\u4e49\u57fa\u672c resultMap &#xff08;\u53ef\u9009&#xff0c;\u4f46\u63a8\u8350&#xff09;<\/p>\n<p>\u4e3a TUser \u548c TRole \u5b9a\u4e49\u6700\u57fa\u7840\u7684 resultMap&#xff0c;\u7528\u4e8e\u6620\u5c04\u5b83\u4eec\u81ea\u8eab\u7684\u57fa\u672c\u5b57\u6bb5\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u590d\u7528\u6027\u3002<\/p>\n<p>XML<\/p>\n<\/p>\n<p>&lt;mapper namespace&#061;&#034;com.bjpowernode.mapper.UserMapper&#034;&gt;<\/p>\n<p>  &lt;resultMap id&#061;&#034;baseUserResultMap&#034; type&#061;&#034;com.bjpowernode.entity.TUser&#034;&gt;<br \/>\n    &lt;id column&#061;&#034;id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;login_act&#034; property&#061;&#034;loginAct&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;name&#034; property&#061;&#034;name&#034;\/&gt;<br \/>\n    &lt;\/resultMap&gt;<\/p>\n<p>  &lt;resultMap id&#061;&#034;baseRoleResultMap&#034; type&#061;&#034;com.bjpowernode.entity.TRole&#034;&gt;<br \/>\n    &lt;id column&#061;&#034;role_id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;role_key&#034; property&#061;&#034;role&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;role_name&#034; property&#061;&#034;name&#034;\/&gt;<br \/>\n  &lt;\/resultMap&gt;<\/p>\n<p>&lt;\/mapper&gt;<\/p>\n<p>\u6b65\u9aa4 2&#xff1a;\u5b9a\u4e49\u5305\u542b\u5173\u8054\u5173\u7cfb\u7684 resultMap<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u4e3b resultMap&#xff0c;\u5b83\u5c06\u4f7f\u7528 &lt;association&gt; \u548c &lt;collection&gt; \u6765\u6620\u5c04\u5173\u8054\u5bf9\u8c61\u3002<\/p>\n<p>XML<\/p>\n<\/p>\n<p>&lt;mapper namespace&#061;&#034;com.bjpowernode.mapper.UserMapper&#034;&gt;<\/p>\n<p>  &lt;resultMap id&#061;&#034;UserWithAssociationsResultMap&#034; type&#061;&#034;com.bjpowernode.entity.TUser&#034;&gt;<br \/>\n    &lt;id column&#061;&#034;id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;login_act&#034; property&#061;&#034;loginAct&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;name&#034; property&#061;&#034;name&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;phone&#034; property&#061;&#034;phone&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;email&#034; property&#061;&#034;email&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;create_by&#034; property&#061;&#034;createBy&#034;\/&gt;<br \/>\n    &lt;result column&#061;&#034;edit_by&#034; property&#061;&#034;editBy&#034;\/&gt;<\/p>\n<p>    &lt;association property&#061;&#034;createByDO&#034; javaType&#061;&#034;com.bjpowernode.entity.TUser&#034;&gt;<br \/>\n      &lt;id column&#061;&#034;create_by_id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n      &lt;result column&#061;&#034;create_by_login_act&#034; property&#061;&#034;loginAct&#034;\/&gt;<br \/>\n      &lt;result column&#061;&#034;create_by_name&#034; property&#061;&#034;name&#034;\/&gt;<br \/>\n      &lt;\/association&gt;<\/p>\n<p>    &lt;association property&#061;&#034;editByDO&#034; javaType&#061;&#034;com.bjpowernode.entity.TUser&#034;&gt;<br \/>\n      &lt;id column&#061;&#034;edit_by_id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n      &lt;result column&#061;&#034;edit_by_login_act&#034; property&#061;&#034;loginAct&#034;\/&gt;<br \/>\n      &lt;result column&#061;&#034;edit_by_name&#034; property&#061;&#034;name&#034;\/&gt;<br \/>\n    &lt;\/association&gt;<\/p>\n<p>    &lt;collection property&#061;&#034;tRoleList&#034; ofType&#061;&#034;com.bjpowernode.entity.TRole&#034;&gt;<br \/>\n      &lt;id column&#061;&#034;role_id&#034; property&#061;&#034;id&#034;\/&gt;<br \/>\n      &lt;result column&#061;&#034;role_key&#034; property&#061;&#034;role&#034;\/&gt;<br \/>\n      &lt;result column&#061;&#034;role_name&#034; property&#061;&#034;name&#034;\/&gt;<br \/>\n    &lt;\/collection&gt;<br \/>\n  &lt;\/resultMap&gt;<\/p>\n<p>&lt;\/mapper&gt;<\/p>\n<p>\u89e3\u91ca\u5173\u952e\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>id&#061;&#034;UserWithAssociationsResultMap&#034;: \u5b9a\u4e49\u4e00\u4e2a\u4f9b SQL \u8bed\u53e5\u5f15\u7528\u7684 resultMap ID\u3002<\/p>\n<\/li>\n<li>\n<p>type&#061;&#034;com.bjpowernode.entity.TUser&#034;: \u6307\u5b9a\u6b64 resultMap \u6620\u5c04\u5230\u7684\u4e3b Java \u5bf9\u8c61\u7c7b\u578b\u3002<\/p>\n<\/li>\n<li>\n<p>association \u548c collection \u5185\u90e8\u7684 column \u5c5e\u6027&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8fd9\u662f\u6700\u6838\u5fc3\u7684\u5730\u65b9\u3002\u5b83\u4e0d\u662f\u76f4\u63a5\u6620\u5c04\u6570\u636e\u5e93\u7684\u539f\u59cb\u5217\u540d&#xff0c;\u800c\u662f\u6620\u5c04\u4f60\u5728 SQL SELECT \u8bed\u53e5\u4e2d\u4e3a\u5173\u8054\u8868\u7684\u5217\u5b9a\u4e49\u7684\u522b\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f8b\u5982&#xff0c;create_by_id\u3001create_by_name\u3001role_id \u7b49&#xff0c;\u8fd9\u4e9b\u522b\u540d\u662f\u4e3a\u4e86\u533a\u5206\u4e3b\u5bf9\u8c61\u548c\u5173\u8054\u5bf9\u8c61\u7684\u540c\u540d\u5c5e\u6027\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>collection \u7684 ofType&#xff1a; \u660e\u786e\u6307\u5b9a\u96c6\u5408 tRoleList \u4e2d\u5143\u7d20\u7684\u5177\u4f53 Java \u7c7b\u578b com.bjpowernode.entity.TRole\u3002MyBatis \u4f1a\u6839\u636e\u8fd9\u4e2a\u7c7b\u578b\u5b9e\u4f8b\u5316\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u6b65\u9aa4 3&#xff1a;\u7f16\u5199 SQL \u67e5\u8be2&#xff08;\u4f7f\u7528 JOIN \u548c\u5217\u522b\u540d&#xff09;<\/p>\n<p>Mapper \u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5&#xff1a;TUser selectUserDetailById(Integer userId);<\/p>\n<p>XML<\/p>\n<\/p>\n<p>&lt;mapper namespace&#061;&#034;com.bjpowernode.mapper.UserMapper&#034;&gt;<\/p>\n<p>  &lt;select id&#061;&#034;selectUserDetailById&#034; resultMap&#061;&#034;UserWithAssociationsResultMap&#034;&gt;<br \/>\n    SELECT<br \/>\n      tu.id,<br \/>\n      tu.login_act,<br \/>\n      tu.name,<br \/>\n      tu.phone,<br \/>\n      tu.email,<br \/>\n      tu.account_no_expired,<br \/>\n      tu.credentials_no_expired,<br \/>\n      tu.account_no_locked,<br \/>\n      tu.account_enabled,<br \/>\n      tu.create_time,<br \/>\n      tu.create_by,<br \/>\n      tu.edit_time,<br \/>\n      tu.edit_by,<br \/>\n      tu.last_login_time,<\/p>\n<p>      &#8212; \u521b\u5efa\u4eba (createByDO) \u7684\u5b57\u6bb5&#xff0c;\u4f7f\u7528 &#096;create_by_&#096; \u524d\u7f00\u522b\u540d<br \/>\n      cbu.id AS create_by_id,<br \/>\n      cbu.login_act AS create_by_login_act,<br \/>\n      cbu.name AS create_by_name,<\/p>\n<p>      &#8212; \u4fee\u6539\u4eba (editByDO) \u7684\u5b57\u6bb5&#xff0c;\u4f7f\u7528 &#096;edit_by_&#096; \u524d\u7f00\u522b\u540d<br \/>\n      ebu.id AS edit_by_id,<br \/>\n      ebu.login_act AS edit_by_login_act,<br \/>\n      ebu.name AS edit_by_name,<\/p>\n<p>      &#8212; \u89d2\u8272 (tRoleList) \u7684\u5b57\u6bb5&#xff0c;\u4f7f\u7528 &#096;role_&#096; \u524d\u7f00\u522b\u540d<br \/>\n      tr.id AS role_id,<br \/>\n      tr.role AS role_key,<br \/>\n      tr.name AS role_name<br \/>\n    FROM<br \/>\n      t_user tu<br \/>\n    LEFT JOIN<br \/>\n      t_user cbu ON tu.create_by &#061; cbu.id &#8212; \u5173\u8054\u521b\u5efa\u4eba<br \/>\n    LEFT JOIN<br \/>\n      t_user ebu ON tu.edit_by &#061; ebu.id   &#8212; \u5173\u8054\u4fee\u6539\u4eba<br \/>\n    LEFT JOIN<br \/>\n      t_user_role tur ON tu.id &#061; tur.user_id &#8212; \u5173\u8054\u7528\u6237-\u89d2\u8272\u4e2d\u95f4\u8868<br \/>\n    LEFT JOIN<br \/>\n      t_role tr ON tur.role_id &#061; tr.id   &#8212; \u5173\u8054\u89d2\u8272\u8868<br \/>\n    WHERE<br \/>\n      tu.id &#061; #{userId}<br \/>\n  &lt;\/select&gt;<\/p>\n<p>&lt;\/mapper&gt;<\/p>\n<p>\u6838\u5fc3\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>LEFT JOIN&#xff1a; \u7528\u4e8e\u8fde\u63a5\u6240\u6709\u76f8\u5173\u7684\u8868&#xff0c;\u786e\u4fdd\u6240\u6709\u6570\u636e\u90fd\u80fd\u5728\u4e00\u6b21\u67e5\u8be2\u4e2d\u8fd4\u56de\u3002<\/p>\n<\/li>\n<li>\n<p>AS \u522b\u540d&#xff1a; \u8fd9\u662f\u5b9e\u73b0 resultMap \u5d4c\u5957\u7ed3\u679c\u6620\u5c04\u7684\u5173\u952e\u3002\u4f60\u5fc5\u987b\u4e3a\u6240\u6709\u5173\u8054\u8868\u7684\u5217\u5b9a\u4e49\u552f\u4e00\u7684\u522b\u540d&#xff0c;\u8fd9\u4e9b\u522b\u540d\u5c06\u4e0e resultMap \u4e2d &lt;association&gt; \u548c &lt;collection&gt; \u5185\u90e8\u7684 column \u5c5e\u6027\u7cbe\u786e\u5339\u914d\u3002MyBatis \u6839\u636e\u8fd9\u4e9b\u522b\u540d\u5c06\u6570\u636e\u6b63\u786e\u5730\u586b\u5145\u5230 createByDO\u3001editByDO \u548c tRoleList \u4e2d\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>\u4e94\u3001\u603b\u7ed3\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h4>\n<\/p>\n<li>\n<p>\u4f18\u5148\u4f7f\u7528\u5d4c\u5957\u7ed3\u679c&#xff08;Eager Loading&#xff09;&#xff1a; \u5927\u591a\u6570\u573a\u666f\u4e0b&#xff0c;\u4e00\u6b21 JOIN \u67e5\u8be2\u914d\u5408 resultMap \u7684\u5d4c\u5957\u7ed3\u679c\u6620\u5c04\u662f\u6700\u9ad8\u6548\u4e14\u63a8\u8350\u7684\u65b9\u5f0f&#xff0c;\u56e0\u4e3a\u5b83\u907f\u514d\u4e86\u6f5c\u5728\u7684 N&#043;1 \u67e5\u8be2\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>\u660e\u786e\u7684\u5217\u522b\u540d&#xff1a; \u5728 SQL \u67e5\u8be2\u4e2d\u4e3a\u5173\u8054\u8868\u7684\u5217\u4f7f\u7528\u6e05\u6670\u3001\u4e0d\u91cd\u590d\u7684\u522b\u540d\u81f3\u5173\u91cd\u8981&#xff0c;\u8fd9\u4e9b\u522b\u540d\u5c06\u4f5c\u4e3a resultMap \u6620\u5c04\u7684\u4f9d\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>&lt;id&gt; \u7684\u91cd\u8981\u6027&#xff1a; \u5728 resultMap \u4e2d&#xff08;\u7279\u522b\u662f &lt;collection&gt; \u5185\u90e8&#xff09;&#xff0c;\u6b63\u786e\u6807\u8bb0\u4e3b\u952e &lt;id&gt; \u662f MyBatis \u6b63\u786e\u805a\u5408\u6570\u636e\u5230\u7236\u5bf9\u8c61\u7684\u5173\u952e\u3002\u5b83\u5e2e\u52a9 MyBatis \u8bc6\u522b\u5e76\u907f\u514d\u91cd\u590d\u521b\u5efa\u7236\u5bf9\u8c61&#xff0c;\u540c\u65f6\u5c06\u6240\u6709\u5b50\u6570\u636e\u6dfb\u52a0\u5230\u6b63\u786e\u7684\u96c6\u5408\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>javaType \u548c ofType&#xff1a; \u52a1\u5fc5\u4e3a &lt;association&gt; \u6307\u5b9a javaType&#xff0c;\u4e3a &lt;collection&gt; \u6307\u5b9a ofType&#xff0c;\u8fd9\u6837 MyBatis \u624d\u80fd\u6b63\u786e\u5730\u5b9e\u4f8b\u5316\u548c\u586b\u5145\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>\u5408\u7406\u89c4\u5212 SQL \u590d\u6742\u5ea6&#xff1a; \u590d\u6742\u7684 JOIN \u8bed\u53e5\u867d\u7136\u80fd\u4e00\u6b21\u6027\u83b7\u53d6\u6240\u6709\u6570\u636e&#xff0c;\u4f46\u8fc7\u5ea6\u590d\u6742\u7684 SQL \u53ef\u80fd\u4f1a\u964d\u4f4e\u53ef\u8bfb\u6027\u548c\u7ef4\u62a4\u6027\u3002\u5728\u5fc5\u8981\u65f6&#xff0c;\u53ef\u4ee5\u8003\u8651\u62c6\u5206\u67e5\u8be2\u6216\u4f7f\u7528 MyBatis \u7684\u4e8c\u7ea7\u7f13\u5b58\u6765\u4f18\u5316\u3002<\/p>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb29\u6b21\u3002\u5927\u591a\u6570\u573a\u666f\u4e0b\uff0c\u4e00\u6b21JOIN\u67e5\u8be2\u914d\u5408resultMap\u7684\u5d4c\u5957\u7ed3\u679c\u6620\u5c04\u662f\u6700\u9ad8\u6548\u4e14\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u907f\u514d\u4e86\u6f5c\u5728\u7684 N+1 \u67e5\u8be2\u95ee\u9898\u3002\u5728 SQL \u67e5\u8be2\u4e2d\u4e3a\u5173\u8054\u8868\u7684\u5217\u4f7f\u7528\u6e05\u6670\u3001\u4e0d\u91cd\u590d\u7684\u522b\u540d\u81f3\u5173\u91cd\u8981\uff0c\u8fd9\u4e9b\u522b\u540d\u5c06\u4f5c\u4e3aresultMap\u6620\u5c04\u7684\u4f9d\u636e\u3002\u5728resultMap\u4e2d\uff08\u7279\u522b\u662f\u5185\u90e8\uff09\uff0c\u6b63\u786e\u6807\u8bb0\u4e3b\u952e\u662f MyBatis \u6b63\u786e\u805a\u5408\u6570\u636e\u5230\u7236\u5bf9\u8c61\u7684\u5173\u952e\u3002\u5b83\u5e2e\u52a9 MyBatis \u8bc6\u522b\u5e76\u907f\u514d\u91cd\u590d\u521b\u5efa\u7236\u5bf9\u8c61\uff0c\u540c\u65f6\u5c06\u6240\u6709\u5b50\u6570\u636e\u6dfb\u52a0\u5230\u6b63\u786e\u7684\u96c6\u5408\u4e2d\u3002javaType\u548cofType\u52a1\u5fc5\u4e3a\u6307\u5b9ajavaType\uff0c\u4e3a\u6307\u5b9aofType\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1769,604,100],"topic":[],"class_list":["post-50194","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-mybatis","tag-oracle","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/50194.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb29\u6b21\u3002\u5927\u591a\u6570\u573a\u666f\u4e0b\uff0c\u4e00\u6b21JOIN\u67e5\u8be2\u914d\u5408resultMap\u7684\u5d4c\u5957\u7ed3\u679c\u6620\u5c04\u662f\u6700\u9ad8\u6548\u4e14\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u907f\u514d\u4e86\u6f5c\u5728\u7684 N+1 \u67e5\u8be2\u95ee\u9898\u3002\u5728 SQL \u67e5\u8be2\u4e2d\u4e3a\u5173\u8054\u8868\u7684\u5217\u4f7f\u7528\u6e05\u6670\u3001\u4e0d\u91cd\u590d\u7684\u522b\u540d\u81f3\u5173\u91cd\u8981\uff0c\u8fd9\u4e9b\u522b\u540d\u5c06\u4f5c\u4e3aresultMap\u6620\u5c04\u7684\u4f9d\u636e\u3002\u5728resultMap\u4e2d\uff08\u7279\u522b\u662f\u5185\u90e8\uff09\uff0c\u6b63\u786e\u6807\u8bb0\u4e3b\u952e\u662f MyBatis \u6b63\u786e\u805a\u5408\u6570\u636e\u5230\u7236\u5bf9\u8c61\u7684\u5173\u952e\u3002\u5b83\u5e2e\u52a9 MyBatis \u8bc6\u522b\u5e76\u907f\u514d\u91cd\u590d\u521b\u5efa\u7236\u5bf9\u8c61\uff0c\u540c\u65f6\u5c06\u6240\u6709\u5b50\u6570\u636e\u6dfb\u52a0\u5230\u6b63\u786e\u7684\u96c6\u5408\u4e2d\u3002javaType\u548cofType\u52a1\u5fc5\u4e3a\u6307\u5b9ajavaType\uff0c\u4e3a\u6307\u5b9aofType\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/50194.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T13:52:09+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/50194.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/50194.html\",\"name\":\"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T13:52:09+00:00\",\"dateModified\":\"2025-07-30T13:52:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/50194.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/50194.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/50194.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/50194.html","og_locale":"zh_CN","og_type":"article","og_title":"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb29\u6b21\u3002\u5927\u591a\u6570\u573a\u666f\u4e0b\uff0c\u4e00\u6b21JOIN\u67e5\u8be2\u914d\u5408resultMap\u7684\u5d4c\u5957\u7ed3\u679c\u6620\u5c04\u662f\u6700\u9ad8\u6548\u4e14\u63a8\u8350\u7684\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u907f\u514d\u4e86\u6f5c\u5728\u7684 N+1 \u67e5\u8be2\u95ee\u9898\u3002\u5728 SQL \u67e5\u8be2\u4e2d\u4e3a\u5173\u8054\u8868\u7684\u5217\u4f7f\u7528\u6e05\u6670\u3001\u4e0d\u91cd\u590d\u7684\u522b\u540d\u81f3\u5173\u91cd\u8981\uff0c\u8fd9\u4e9b\u522b\u540d\u5c06\u4f5c\u4e3aresultMap\u6620\u5c04\u7684\u4f9d\u636e\u3002\u5728resultMap\u4e2d\uff08\u7279\u522b\u662f\u5185\u90e8\uff09\uff0c\u6b63\u786e\u6807\u8bb0\u4e3b\u952e\u662f MyBatis \u6b63\u786e\u805a\u5408\u6570\u636e\u5230\u7236\u5bf9\u8c61\u7684\u5173\u952e\u3002\u5b83\u5e2e\u52a9 MyBatis \u8bc6\u522b\u5e76\u907f\u514d\u91cd\u590d\u521b\u5efa\u7236\u5bf9\u8c61\uff0c\u540c\u65f6\u5c06\u6240\u6709\u5b50\u6570\u636e\u6dfb\u52a0\u5230\u6b63\u786e\u7684\u96c6\u5408\u4e2d\u3002javaType\u548cofType\u52a1\u5fc5\u4e3a\u6307\u5b9ajavaType\uff0c\u4e3a\u6307\u5b9aofType\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/50194.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T13:52:09+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/50194.html","url":"https:\/\/www.wsisp.com\/helps\/50194.html","name":"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T13:52:09+00:00","dateModified":"2025-07-30T13:52:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/50194.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/50194.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/50194.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"MyBatis resultMap \u6df1\u5ea6\u89e3\u6790\uff1a\u6784\u5efa\u9ad8\u6548\u7684\u5173\u8054\u67e5\u8be2"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/50194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=50194"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/50194\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=50194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=50194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=50194"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=50194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}