﻿{"id":158,"date":"2016-03-28T22:26:26","date_gmt":"2016-03-28T14:26:26","guid":{"rendered":"http:\/\/www.chenweikang.top\/?p=158"},"modified":"2016-03-28T22:26:26","modified_gmt":"2016-03-28T14:26:26","slug":"mybatis%e5%ad%a6%e4%b9%a0%e4%b9%8b%e8%b7%af-%e4%bd%bf%e7%94%a8%e6%b3%a8%e8%a7%a3%e9%85%8d%e7%bd%ae%e6%98%a0%e5%b0%84","status":"publish","type":"post","link":"https:\/\/www.chenweikang.top\/?p=158","title":{"rendered":"Mybatis\u5b66\u4e60\u4e4b\u8def\u2014\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u6620\u5c04"},"content":{"rendered":"<h2>\u4e00\u3001\u914d\u7f6e\u57fa\u672c\u7684\u589e\u5220\u6539\u67e5\u53ca\u7ed3\u679c\u96c6<\/h2>\n<blockquote>\n<p style=\"padding-left: 30px;\">\u76f4\u63a5\u5728mapper\u63a5\u53e3\u65b9\u6cd5\u540d\u4e0a\u4f7f\u7528\u6ce8\u89e3<\/p>\n<p>@Insert(\"insert into employee (username,salary,deptID) \"<br \/>\n+ \" values(#{username},#{salary},#{dept.id})\")<br \/>\npublic int insertEmp(Employee emp);<\/p>\n<p>@Update(\"UPDATE employee SET \"<br \/>\n+ \" username=#{username}, salary=#{salary} \"<br \/>\n+ \" WHERE id=${id}\")<br \/>\npublic int update(Employee emp);<\/p>\n<p>@Delete(\"DELETE FROM employee WHERE id=#{id}\")<br \/>\npublic int delete(Integer id);<\/p>\n<p>@Select(\"SELECT * FROM employee\")<br \/>\n@Results( \/\/\u5982\u679c\u5217\u540d\u79f0\u548c\u5c5e\u6027\u540d\u79f0\u76f8\u540c\u53ef\u4ee5\u4e0d\u5fc5\u914d\u7f6e<br \/>\n{<br \/>\n@Result(id=true,column=\"id\",property=\"id\"),<br \/>\n@Result(column=\"username\",property=\"username\"),<br \/>\n@Result(column=\"salary\",property=\"salary\")<br \/>\n}<br \/>\n)<br \/>\npublic List&lt;Employee&gt; findEmps();<\/p>\n<p>@Select(\"SELECT * FROM employee WHERE id=#{ids}\")<br \/>\npublic Employee FindById(Integer id);<\/p>\n<p>\u8c03\u7528\u65b9\u5f0f\u548cxml\u914d\u7f6e\u4e00\u6837<\/p><\/blockquote>\n<h2>\u4e8c\u3001\u914d\u7f6e\u6620\u5c04\u5173\u7cfb<\/h2>\n<blockquote><p>\n\u6ce8\u610f\uff1a\u5982\u679c\u6570\u636e\u5e93\u5217\u540d\u548c\u5c5e\u6027\u540d\u79f0\u4e0d\u540c \u5fc5\u987b\u4f7f\u7528\u5982\u4e0b\u5b9a\u4e49\u6620\u5c04<br \/>\n@Results(<br \/>\n{<br \/>\n@Result(id=true,column=\"id\",property=\"id\"),<br \/>\n@Result(column=\"username\",property=\"username\"),<br \/>\n@Result(column=\"salary\",property=\"salary\")<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u4e00\u5bf9\u4e00\u7684\u914d\u7f6e<\/p>\n<p>one=@One(select=\"com.cwk.dao.DepartmentMapper.findById\")<br \/>\ncolumn=\"deptID\" \uff1a\u5916\u952e<br \/>\nproperty=\"dept\" \uff1a\u5c5e\u6027\u540d\u79f0<br \/>\n\u8c03\u7528 DepartmentMapper\u4e2d\u7684\u65b9\u6cd5 findById<\/p>\n<p>@Select(\"SELECT * FROM employee WHERE id=#{id}\")<br \/>\n@Results( \/\/\u5982\u679c\u5217\u540d\u79f0\u548c\u5c5e\u6027\u540d\u79f0\u76f8\u540c\u53ef\u4ee5\u4e0d\u5fc5\u914d\u7f6e<br \/>\n{<br \/>\n@Result(id=true,column=\"id\",property=\"id\"),<br \/>\n@Result(column=\"username\",property=\"username\"),<br \/>\n@Result(column=\"salary\",property=\"salary\"),<br \/>\n@Result(column=\"deptID\",property=\"dept\" ,one=@One(select=\"com.cwk.dao.DepartmentMapper.findById\"))<br \/>\n}<br \/>\n)<br \/>\npublic Employee findEmpWidthDept(Integer id);<\/p>\n<p>&nbsp;<\/p>\n<p>2. \u4e00\u5bf9\u591a\u914d\u7f6e<br \/>\ncolumn=\"id\" : \u4f20\u7ed9\u8c03\u7528\u65b9\u6cd5\u7684\u53c2\u6570<br \/>\nproperty=\"emps\" \u83b7\u53d6\u5230\u7684\u7ed3\u679c\u5c06\u4ed8\u7ed9\u6b64\u5c5e\u6027<br \/>\n@Many(select=\"com.cwk.dao.EmployeeMapper.findEmpByDeptId\")<br \/>\n\u8c03\u7528\u6307\u5b9a\u7684\u67e5\u8be2\u65b9\u6cd5 \uff08\u8fd4\u56de\u96c6\u5408\u7c7b\u578b\uff09<\/p>\n<p>\/\/\u901a\u8fc7id\u67e5\u8be2 \u90e8\u95e8+\u6240\u6709\u5458\u5de5 (\u4e00\u4e2a\u90e8\u95e8\u5bf9\u5e94\u591a\u4e2a\u96c7\u5458)<br \/>\n@Select(\"SELECT * FROM department where id=#{id}\")<br \/>\n@Results({<br \/>\n@Result(id=true,column=\"id\",property=\"id\"),<br \/>\n@Result(column=\"dept_name\",property=\"deptName\"),<br \/>\n@Result(column=\"dept_desc\",property=\"deptDesc\"),<br \/>\n@Result(column=\"id\" ,property=\"emps\" ,many=@Many(select=\"com.cwk.dao.EmployeeMapper.findEmpByDeptId\"))<br \/>\n})<br \/>\npublic Department findDeptAndEmpsById(int id);<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #000000;\"><em>\u603b\u7ed3\uff1a\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u7701\u53bb\u4e86xml\u914d\u7f6e\u6587\u4ef6 \u4f7f\u7528\u6bd4\u8f83\u65b9\u4fbf\uff0c\u4f46\u662f\u5728\u914d\u7f6e\u590d\u6742\u7684\u5173\u8054\u5173\u7cfb\u65f6\u6ca1\u6709xml\u914d\u7f6e\u65b9\u5f0f\u5bb9\u6613\uff0c\u5176\u6b21\u5728\u7ef4\u62a4\u65f6xml\u914d\u7f6e\u66f4\u597d\uff0c\u6240\u4ee5\u5728\u9879\u76ee\u6bd4\u8f83\u5c0f\u65f6\u53ef\u4ee5\u4f7f\u7528\u6ce8\u89e3\u65b9\u5f0f\u3002<\/em><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.chenweikang.top\">\u5de6\u624b\u4ee3\u7801\u53f3\u624b\u8bd7<\/a> &raquo; <a href=\"https:\/\/www.chenweikang.top\/?p=158\">Mybatis\u5b66\u4e60\u4e4b\u8def\u2014\u4f7f\u7528\u6ce8\u89e3\u914d\u7f6e\u6620\u5c04<\/a><\/p><div class=\"__youshang\">\r\n            <div id=\"__youshang_popup\" class=\"wechat popup\" style=\"display: none;\">\r\n                <div class=\"head\">~\u8c22\u8c22\u6253\u8d4f~<\/div>\r\n                <div class=\"qrcode\"><div class=\"qrcode-li wechat\" ><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/wexin.png\" \/><\/div><div class=\"qrcode-li alipay\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-pay.png\" \/><\/div><div class=\"qrcode-li hongbao\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-hongbao.png\" \/><\/div><\/div>\r\n                <ul class=\"platform\"><li class=\"icon-wechat active\" data-bg-color=\"#05af4e\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-alipay \" data-bg-color=\"#00a2ea\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-hongbao \" data-bg-color=\"#dd5746\" data-thanks=\"<p>\u626b\u7801\u9886\u7ea2\u5305<\/p><p style='margin-top: 24px;'>\uff08\u4f59\u989d\u5b9d\u652f\u4ed8\u65f6\u53ef\u62b5\u73b0\uff09<\/p>\"><\/li><\/ul>\r\n            <\/div>\r\n            <a href=\"javascript:void(0);\" id=\"__youshang_btn\">\u8d4f<\/a>\r\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u914d\u7f6e\u57fa\u672c\u7684\u589e\u5220\u6539\u67e5\u53ca\u7ed3\u679c\u96c6 \u76f4\u63a5\u5728mapper\u63a5\u53e3\u65b9\u6cd5\u540d\u4e0a\u4f7f\u7528\u6ce8\u89e3 @Insert(\"insert int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":138,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,3],"tags":[20,32],"class_list":["post-158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-note","tag-java","tag-mybatis"],"_links":{"self":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":0,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/media\/138"}],"wp:attachment":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}