{"id":1982,"date":"2017-06-15T20:53:23","date_gmt":"2017-06-15T12:53:23","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1982"},"modified":"2020-02-05T11:02:38","modified_gmt":"2020-02-05T03:02:38","slug":"mybatis%e5%a4%9a%e8%a1%a8%e5%85%b3%e8%81%94%e6%9f%a5%e8%af%a2%e4%b9%8b%e5%a4%9a%e5%af%b9%e4%b8%80%e5%92%8c%e4%b8%80%e5%af%b9%e5%a4%9a","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1982","title":{"rendered":"Mybatis\u591a\u8868\u5173\u8054\u67e5\u8be2\u4e4b\u591a\u5bf9\u4e00\u548c\u4e00\u5bf9\u591a"},"content":{"rendered":"<p>Mybatis\u591a\u8868\u5173\u8054\u53ef\u5206\u6210\u56db\u79cd\u60c5\u51b5:\u4e00\u5bf9\u4e00, \u4e00\u5bf9\u591a, \u591a\u5bf9\u4e00, \u591a\u5bf9\u591a.\u5b9e\u73b0\u6620\u5c04\u7684\u5173\u952e\u662fresultMap\u7f51\u4e0a\u6709\u5f88\u591a\u4ecb\u7ecd\u53ef\u81ea\u884c\u641c\u7d22\u5b66\u4e60\uff0c\u5982:<a class=\"quote_title\" href=\"http:\/\/limingnihao.iteye.com\/blog\/781878\" target=\"_blank\">MyBatis\u5b66\u4e60 \u4e4b \u4e8c\u3001SQL\u8bed\u53e5\u6620\u5c04\u6587\u4ef6(1)resultMap<\/a><\/p>\n<h2>\u9996\u5148\u770b\u4e0b\u591a\u5bf9\u4e00\u5b9e\u73b0<\/h2>\n<h3>\u51c6\u5907\u4e24\u5f20\u8868person\u548corder\u4e3a1:n\u5173\u7cfb<\/h3>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/person_order.png\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1983\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/person_order.png\" alt=\"person_order\" width=\"537\" height=\"132\" \/><\/a><\/p>\n<h3>\u7c7b\u7ed3\u6784\uff1a<\/h3>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1984\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/class7.png\" alt=\"class7\" width=\"724\" height=\"163\" \/><\/p>\n<h3>\u6620\u5c04\u6587\u4ef6:OrderMapper.xml<\/h3>\n<h4>\u7b2c\u4e00\u79cd\u6620\u5c04\u65b9\u5f0f:<\/h4>\n<p>[java]&lt;mapper namespace=&quot;com.ittx.mybatis.demo1.dao.OrderDao&quot;&gt;<br \/>\n\t&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Order&quot; id=&quot;orderBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;orderId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderNumber&quot; property=&quot;number&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderPrice&quot; property=&quot;price&quot;\/&gt;<br \/>\n\t\t&lt;!&#8211; \u591a\u5bf9\u4e00\u7684\u5173\u7cfb &#8211;&gt;<br \/>\n\t\t&lt;!&#8211;column:\u6307\u5916\u952e\u503c\uff0c property: \u6307\u7684\u662f\u5c5e\u6027\u7684\u503c, javaType\uff1a\u6307\u7684\u662f\u5c5e\u6027\u7684\u7c7b\u578b&#8211;&gt;<br \/>\n\t\t&lt;association column=&quot;pid&quot; property=&quot;person&quot; javaType=&quot;com.ittx.mybatis.demo1.model.Person&quot;&gt;<br \/>\n\t\t\t&lt;id column=&quot;personId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t\t&lt;result column=&quot;personName&quot; property=&quot;name&quot;\/&gt;<br \/>\n\t\t\t&lt;result column=&quot;personAddress&quot; property=&quot;address&quot;\/&gt;<br \/>\n\t\t\t&lt;result column=&quot;personTel&quot; property=&quot;tel&quot;\/&gt;<br \/>\n\t\t&lt;\/association&gt;<br \/>\n\t&lt;\/resultMap&gt;<\/p>\n<p>\t&lt;!&#8211; \u6839\u636eid\u67e5\u8be2Order, \u5173\u8054\u5c06Person\u67e5\u8be2\u51fa\u6765 &#8211;&gt;<br \/>\n\t&lt;select id=&quot;selectOrderById&quot; parameterType=&quot;string&quot; resultMap=&quot;orderBean&quot;&gt;<br \/>\n\t\tselect p.*, o.* from person p, orders o where p.personId  = o.pid and o.orderId = #{id}<br \/>\n\t&lt;\/select&gt;<br \/>\n&lt;\/mapper&gt;[\/java]<\/p>\n<h4>\u7b2c\u4e8c\u79cd\u6620\u5c04\u65b9\u5f0f\uff1a<\/h4>\n<p>[java]&lt;mapper namespace=&quot;com.ittx.mybatis.demo1.dao.OrderDao&quot;&gt;<br \/>\n\t&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Person&quot; id=&quot;personBaseBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;personId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personName&quot; property=&quot;name&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personAddress&quot; property=&quot;address&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personTel&quot; property=&quot;tel&quot;\/&gt;<br \/>\n\t&lt;\/resultMap&gt;<\/p>\n<p>\t&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Order&quot; id=&quot;orderBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;orderId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderNumber&quot; property=&quot;number&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderPrice&quot; property=&quot;price&quot;\/&gt;<br \/>\n\t\t&lt;!&#8211; \u591a\u5bf9\u4e00\u7684\u5173\u7cfb &#8211;&gt;<br \/>\n\t\t&lt;!&#8211;column:\u6307\u5916\u952e\u503c\uff0c property: \u6307\u7684\u662f\u5c5e\u6027\u7684\u503c, resultMap\uff1a\u6307\u7684\u662f\u5c5e\u6027\u7684\u6620\u5c04, &#8211;&gt;<br \/>\n\t\t&lt;association column=&quot;pid&quot; property=&quot;person&quot; resultMap=&quot;com.ittx.mybatis.demo1.dao.OrderDao.personBaseBean&quot;\/&gt;<br \/>\n\t&lt;\/resultMap&gt;<\/p>\n<p>\t&lt;!&#8211; \u6839\u636eid\u67e5\u8be2Order, \u5173\u8054\u5c06Person\u67e5\u8be2\u51fa\u6765 &#8211;&gt;<br \/>\n\t&lt;select id=&quot;selectOrderById&quot; parameterType=&quot;string&quot; resultMap=&quot;orderBean&quot;&gt;<br \/>\n\t\tselect p.*, o.* from person p, orders o where p.personId  = o.pid and o.orderId = #{id}<br \/>\n\t&lt;\/select&gt;<br \/>\n&lt;\/mapper&gt;[\/java]<\/p>\n<h4>\u7b2c\u4e09\u79cd\u6620\u5c04\u65b9\u5f0f:<\/h4>\n<p>[java]&lt;mapper namespace=&quot;com.ittx.mybatis.demo1.dao.OrderDao&quot;&gt;<br \/>\n&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Order&quot; id=&quot;orderBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;orderId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderNumber&quot; property=&quot;number&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderPrice&quot; property=&quot;price&quot;\/&gt;<br \/>\n\t\t&lt;!&#8211; \u591a\u5bf9\u4e00\u7684\u5173\u7cfb &#8211;&gt;<br \/>\n\t\t&lt;!&#8211;column:\u6307\u5916\u952e\u503c\uff0c property: \u6307\u7684\u662f\u5c5e\u6027\u7684\u503c, select:\u4f7f\u7528\u53e6\u4e00\u4e2a\u67e5\u8be2\u5c01\u88c5\u7684\u7ed3\u679c &#8211;&gt;<br \/>\n\t\t&lt;association column=&quot;orderId&quot; property=&quot;person&quot; select=&quot;selectPersonByOrderId&quot;\/&gt;<br \/>\n\t&lt;\/resultMap&gt;<\/p>\n<p>\t&lt;select id=&quot;selectOrderById&quot; parameterType=&quot;string&quot;  resultMap=&quot;orderBean&quot;&gt;<br \/>\n\t\tselect * from orders where orderId = #{id}<br \/>\n\t&lt;\/select&gt;<\/p>\n<p>\t&lt;select id=&quot;selectPersonByOrderId&quot; parameterType=&quot;string&quot; resultMap=&quot;com.ittx.mybatis.demo1.dao.OrderDao.personBaseBean&quot;&gt;<br \/>\n\t\tselect * from person where personId in (select pid from orders where orderId = #{id})<br \/>\n\t&lt;\/select&gt;<br \/>\n&lt;\/mapper&gt;[\/java]<\/p>\n<h2>\u63a5\u7740\u770b\u4e00\u5bf9\u591a\u5173\u8054\u5b9e\u73b0<\/h2>\n<h3>\u8868\u7ed3\u6784\u4e0d\u53d8<br \/>\n\u7c7b\u7ed3\u6784\u5982\u4e0b:<\/h3>\n<p><a href=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/\u4e00\u5bf9\u591a.jpg\" rel=\"fancybox\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-2411\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2017\/06\/\u4e00\u5bf9\u591a.jpg\" alt=\"\u4e00\u5bf9\u591a\" width=\"669\" height=\"252\" \/><\/a><\/p>\n<h3>\u6620\u5c04\u6587\u4ef6:PersonMapper.xml<\/h3>\n<h4>\u7b2c\u4e00\u79cd\u65b9\u5f0f<\/h4>\n<p>[java]&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Person&quot; id=&quot;personBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;personId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personName&quot; property=&quot;name&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personAddress&quot; property=&quot;address&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personTel&quot; property=&quot;tel&quot;\/&gt;<\/p>\n<p>\t\t&lt;!&#8211; \u4e00\u5bf9\u591a\u7684\u5173\u7cfb &#8211;&gt;<br \/>\n\t\t&lt;!&#8211; property: \u6307\u7684\u662f\u96c6\u5408\u5c5e\u6027\u7684\u503c, ofType\uff1a\u6307\u7684\u662f\u96c6\u5408\u4e2d\u5143\u7d20\u7684\u7c7b\u578b &#8211;&gt;<br \/>\n\t\t&lt;collection property=&quot;orders&quot; ofType=&quot;com.ittx.mybatis.demo1.model.Order&quot;&gt;<br \/>\n\t\t\t&lt;id column=&quot;orderId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t\t&lt;result column=&quot;orderNumber&quot; property=&quot;number&quot;\/&gt;<br \/>\n\t\t\t&lt;result column=&quot;orderPrice&quot; property=&quot;price&quot;\/&gt;<br \/>\n\t\t&lt;\/collection&gt;<br \/>\n\t&lt;\/resultMap&gt;<\/p>\n<p>\t&lt;!&#8211; \u6839\u636eid\u67e5\u8be2Person, \u5173\u8054\u5c06Orders\u67e5\u8be2\u51fa\u6765 &#8211;&gt;<br \/>\n\t&lt;select id=&quot;selectPersonById&quot; parameterType=&quot;string&quot; resultMap=&quot;personBean&quot;&gt;<br \/>\n\t\tselect p.*, o.* from person p, orders o where p.personId  = o.pid and p.personId = #{id}<br \/>\n\t&lt;\/select&gt;[\/java]<\/p>\n<h4>\u7b2c\u4e8c\u79cd\u65b9\u5f0f<\/h4>\n<p>[java]&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Order&quot; id=&quot;orderBaseBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;orderId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderNumber&quot; property=&quot;number&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;orderPrice&quot; property=&quot;price&quot;\/&gt;<br \/>\n\t&lt;\/resultMap&gt;<br \/>\n\t&lt;resultMap type=&quot;com.ittx.mybatis.demo1.model.Person&quot; id=&quot;personBean&quot;&gt;<br \/>\n\t\t&lt;id column=&quot;personId&quot; property=&quot;id&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personName&quot; property=&quot;name&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personAddress&quot; property=&quot;address&quot;\/&gt;<br \/>\n\t\t&lt;result column=&quot;personTel&quot; property=&quot;tel&quot;\/&gt;<\/p>\n<p>\t\t&lt;!&#8211; \u4e00\u5bf9\u591a\u7684\u5173\u7cfb &#8211;&gt;<br \/>\n\t\t&lt;collection property=&quot;orders&quot; resultMap=&quot;com.ittx.mybatis.demo1.dao.OrderDao.orderBaseBean&quot;\/&gt;<br \/>\n\t&lt;\/resultMap&gt;<\/p>\n<p>\t&lt;!&#8211; \u6839\u636eid\u67e5\u8be2Person, \u5173\u8054\u5c06Orders\u67e5\u8be2\u51fa\u6765 &#8211;&gt;<br \/>\n\t&lt;select id=&quot;selectPersonById&quot; parameterType=&quot;string&quot; resultMap=&quot;personBean&quot;&gt;<br \/>\n\t\tselect p.*, o.* from person p, orders o where p.personId  = o.pid and p.personId = #{id}<br \/>\n\t&lt;\/select&gt;[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mybatis\u591a\u8868\u5173\u8054\u53ef\u5206\u6210\u56db\u79cd\u60c5\u51b5:\u4e00\u5bf9\u4e00, \u4e00\u5bf9\u591a, \u591a\u5bf9\u4e00, \u591a\u5bf9\u591a.\u5b9e\u73b0\u6620\u5c04\u7684\u5173\u952e\u662fresultMap [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[92],"tags":[],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1982"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1982"}],"version-history":[{"count":8,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1982\/revisions"}],"predecessor-version":[{"id":2412,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1982\/revisions\/2412"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}