
{"id":2873,"date":"2020-12-31T11:39:05","date_gmt":"2020-12-31T03:39:05","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2873"},"modified":"2020-12-31T13:52:50","modified_gmt":"2020-12-31T05:52:50","slug":"2020java%e6%a1%86%e6%9e%b6%e6%95%99%e7%a8%8b%e4%b9%8bmybatis%e5%b5%8c%e5%a5%97%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2873","title":{"rendered":"2020java\u6846\u67b6\u6559\u7a0b\u4e4bmybatis\u5d4c\u5957\u67e5\u8be2\u4ee5\u53ca\u5ef6\u8fdf\u52a0\u8f7d"},"content":{"rendered":"<h2>2020java\u6846\u67b6\u6559\u7a0b\u4e4bmybatis\u5d4c\u5957\u67e5\u8be2\u4ee5\u53ca\u5ef6\u8fdf\u52a0\u8f7d<\/h2>\n<h2><strong>\u4e00\u5bf9\u4e00\u67e5\u8be2<\/strong><\/h2>\n<p><strong>\u7528\u6237\u4e0e\u7b80\u5386<\/strong><\/p>\n<p><strong>1.\u6570\u636e\u5e93\u8868:<\/strong><\/p>\n<p>\u7b80\u5386\u6570\u636e\u5e93\u8868\uff1a<!--more--><\/p>\n<pre>CREATE TABLE `resume` (\r\n  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n  `resume_name` varchar(50) NOT NULL,\r\n  `resume_uid` int(11) DEFAULT NULL,\r\n  PRIMARY KEY (`id`),\r\n  UNIQUE KEY `resume_uid` (`resume_uid`),\r\n  CONSTRAINT `resume_ibfk_1` FOREIGN KEY (`resume_uid`) REFERENCES `member` (`uid`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8<\/pre>\n<p>\u7528\u6237\u6570\u636e\u5e93\u8868\uff1a<\/p>\n<pre>CREATE TABLE `member` (\r\n  `uid` int(11) NOT NULL AUTO_INCREMENT,\r\n  `username` varchar(50) NOT NULL,\r\n  `sex` varchar(2) NOT NULL,\r\n  PRIMARY KEY (`uid`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8<\/pre>\n<h3><strong>2.\u5728\u4e24\u4e2a\u5b9e\u4f53\u7c7b\u521b\u5efa\u5bf9\u65b9\u5b9e\u4f53\u5c5e\u6027<\/strong><\/h3>\n<h3>3.\u914d\u7f6emapper.xml<\/h3>\n<p><strong>\u7528\u6237\u7684mapper.xml<\/strong><\/p>\n<pre>&lt;resultMap id=\"BaseResultMap\" type=\"com.evshou.admin.entity.Member\" &gt;\r\n  &lt;id column=\"uid\" property=\"uid\" jdbcType=\"INTEGER\" \/&gt;\r\n  &lt;result column=\"username\" property=\"username\" jdbcType=\"VARCHAR\" \/&gt;\r\n  &lt;result column=\"sex\" property=\"sex\" jdbcType=\"VARCHAR\" \/&gt;\r\n&lt;\/resultMap&gt;\r\n&lt;select id=\"queryMemberByUid\" resultMap=\"BaseResultMap\"&gt;\r\n  select * from member where uid=#{uid}\r\n&lt;\/select&gt;<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/30\/8.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u7b80\u5386\u7684mapper.xml<\/strong><\/p>\n<pre>&lt;resultMap id=\"BaseResultMap\" type=\"com.evshou.admin.entity.Resume\" &gt;\r\n  &lt;id column=\"id\" property=\"id\" jdbcType=\"INTEGER\" \/&gt;\r\n  &lt;result column=\"resume_name\" property=\"resumeName\" jdbcType=\"VARCHAR\" \/&gt;\r\n  &lt;result column=\"resume_uid\" property=\"resumeUid\" jdbcType=\"INTEGER\" \/&gt;\r\n  &lt;association property=\"member\" javaType=\"Member\"\r\n               select=\"com.evshou.admin.mapper.MemberMapper.queryMemberByUid\"\r\n               column=\"resume_uid\"\/&gt;\r\n&lt;\/resultMap&gt;\r\n&lt;select id=\"queryResumeByUId\" resultMap=\"BaseResultMap\"&gt;\r\n  select  * from resume where resume_uid=#{uid}\r\n&lt;\/select&gt;<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/30\/9.png\" alt=\"\" width=\"680\" \/><\/p>\n<h3>4.\u521b\u5efa\u63a5\u53e3<\/h3>\n<p><strong>\u7528\u6237\u63a5\u53e3\uff1a<\/strong><\/p>\n<pre>Member queryMemberByUid();<\/pre>\n<p><strong>\u7b80\u5386\u63a5\u53e3\uff1a<\/strong><\/p>\n<pre>Resume queryResumeByUId(Integer uid);<\/pre>\n<h3>5.\u6d4b\u8bd5<\/h3>\n<pre>@Test\r\npublic void queryResumeByUId(){\r\n    SqlSession ss = MybatisUtils.getSqlSession();\r\n    ResumeMapper rm = ss.getMapper(ResumeMapper.class);\r\n    Resume resume = rm.queryResumeByUId(1);\r\n    System.out.println(resume);\r\n    System.out.println(resume.getMember());\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/30\/10.png\" alt=\"\" width=\"680\" \/><\/p>\n<hr \/>\n<h2>\u4e00\u5bf9\u591a\u548c\u591a\u5bf9\u4e00<\/h2>\n<p><strong>\u90e8\u95e8\u4e0e\u5458\u5de5<\/strong><\/p>\n<p><strong><span style=\"color: #ff0000;\">\u901a\u8fc7\u90e8\u95e8\u7f16\u53f7\u67e5\u8be2\u90e8\u95e8\u6240\u5728\u7684\u5458\u5de5\uff0c\u6240\u4ee5\u5458\u5de5\u662fList\u96c6\u5408<\/span><\/strong><\/p>\n<p><strong>1.\u6570\u636e\u5e93\u8868<\/strong><\/p>\n<pre>create table dept(#\u90e8\u95e8\r\n    id int primary key  auto_increment,\r\n    name varchar(50) ,\r\n    loc varchar(100)\r\n)charset=utf8;\r\ncreate table emp(#\u5458\u5de5\r\n    id int auto_increment primary key ,\r\n    name varchar(50),\r\n    salary double,\r\n    dep_id int ,\r\n    foreign key (dep_id) references dept(id)\r\n)charset=utf8;<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/31\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>2.\u5b9e\u4f53\u7c7b<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/31\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>3.\u63a5\u53e3<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/31\/3.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>4.\u6620\u5c04\u6587\u4ef6<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/31\/4.png\" alt=\"\" width=\"680\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/31\/5.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>5.\u6d4b\u8bd5\u4ee3\u7801<\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/31\/6.png\" alt=\"\" width=\"680\" \/><\/p>\n<hr \/>\n<h3>\u5ef6\u8fdf\u52a0\u8f7d(\u4e86\u89e3)<\/h3>\n<p>\u5728mybatis-config.xml\u914d\u7f6e\u5ef6\u8fdf\u52a0\u8f7d<\/p>\n<pre>&lt;settings&gt;\r\n    &lt;!-- \u5f53\u4f7f\u7528\u5d4c\u5957\u67e5\u8be2\u65f6\uff0c\u5982\u679c\u67e5\u8be2\u4e2d\u53ea\u7528\u5230\u4e86\u4e00\u65b9\u7684\u6570\u636e\uff0c\u5219\u4e0d\u4f1a\u89e6\u53d1\u53e6\u4e00\u65b9\u7684\u67e5\u8be2 --&gt;\r\n    &lt;setting name=\"lazyLoadingEnabled\" value=\"true\"\/&gt;&lt;!--\u5f00\u542f\u5ef6\u8fdf\u52a0\u8f7d(\u9ed8\u8ba4false)--&gt;\r\n&lt;\/settings&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u6846\u67b6\u6559\u7a0b\u4e4bmybatis\u5d4c\u5957\u67e5\u8be2\u4ee5\u53ca\u5ef6\u8fdf\u52a0\u8f7d \u4e00\u5bf9\u4e00\u67e5\u8be2 \u7528\u6237\u4e0e\u7b80\u5386 1.\u6570\u636e\u5e93\u8868: \u7b80\u5386\u6570\u636e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2873","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2873"}],"version-history":[{"count":6,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2873\/revisions"}],"predecessor-version":[{"id":2879,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2873\/revisions\/2879"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}