{"id":1106,"date":"2020-03-19T17:46:09","date_gmt":"2020-03-19T09:46:09","guid":{"rendered":"http:\/\/www.rain1024.com\/?p=1106"},"modified":"2023-08-07T20:57:24","modified_gmt":"2023-08-07T12:57:24","slug":"%e5%85%b3%e4%ba%8emybatis-plus%e4%b8%adservice%e5%92%8cmapper%e7%9a%84%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"http:\/\/rain1024.com\/index.php\/2020\/03\/19\/%e5%85%b3%e4%ba%8emybatis-plus%e4%b8%adservice%e5%92%8cmapper%e7%9a%84%e5%88%86%e6%9e%90\/","title":{"rendered":"\u5173\u4e8emybatis-plus\u4e2dService\u548cMapper\u7684\u5206\u6790"},"content":{"rendered":"<h1>\u5173\u4e8emybatis-plus\u4e2dService\u548cMapper\u7684\u5206\u6790<\/h1>\n<h4>\u5728\u540e\u7aef\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u6709\u7528\u5230mybatis-plus\uff0c\u80af\u5b9a\u4f1a\u53d1\u73b0\u5728\u5176\u5185\u90e8\u5b58\u5728\u7740\u4e24\u79cd\u6570\u636e\u5e93\u64cd\u4f5c\u63a5\u53e3\uff0cIservice\u548cBaseMapper\uff0c\u5982\u679c\u53ea\u662f\u7528\u589e\u5220\u6539\u67e5\u4f1a\u53d1\u73b0\u4e24\u8005\u7684\u529f\u80fd\u662f\u4e00\u81f4\u7684\uff0c\u9664\u4e86\u65b9\u6cd5\u540d\u79f0\u6709\u6240\u4e0d\u540c\uff0c\u5176\u4ed6\u7684\u57fa\u672c\u76f8\u4f3c\u3002\u5bf9\u6b64\uff0c\u6211\u9887\u4e3a\u597d\u5947\uff0c\u4fbf\u6253\u5f00\u4e24\u4e2a\u63a5\u53e3\u7684\u6e90\u7801\u8fdb\u884c\u5bf9\u6bd4\u3002<\/h4>\n<h4>\u5148\u6f14\u793a\u4e00\u4e0b\u57fa\u672c\u5f00\u53d1\u4e2d\u7684\u7ee7\u627f\u5173\u7cfb\uff0c\u624b\u52a8\u521b\u5efa\u7684Service\u7ee7\u627f\u4e8eServiceImpl\uff0c\u5e76\u52a0\u8f7d\u81ea\u5df1\u521b\u5efa\u7684Mapper<\/h4>\n<pre><code>@Service\npublic class RestDeptService extends ServiceImpl&lt;RestDeptMapper, RestDept&gt; {\n\n    @Resource\n    private RestDeptMapper restDeptMapper;\n\n }\n\n public interface RestDeptMapper extends BaseMapper&lt;RestDept&gt; {\n\n }\n\n<\/code><\/pre>\n<h4>\u5982\u4e0a\uff0c\u5c31\u662f\u4e00\u822c\u5f00\u53d1\u7684\u57fa\u672c\u6a21\u7248\u4ee3\u7801\uff0c\u8db3\u4ee5\u6ee1\u8db3\u5404\u79cd\u9700\u6c42\u529f\u80fd\uff0c\u4f46\u70b9\u5f00\u6e90\u7801\u65f6\uff0c\u4fbf\u8fdb\u5165\u65b0\u4e16\u754c\u7684\u5927\u95e8\u3002<\/h4>\n<h4>\u5148\u770b\u4e00\u4e0b\u7ee7\u627f\u7ed3\u6784<\/h4>\n<p><img decoding=\"async\" src=\"http:\/\/cos.rain1024.com\/markdown\/image-20200319140641414.png\" alt=\"image-20200319140641414\" \/><\/p>\n<h4>\u8fd9\u6837\u770b\uff0c\u662f\u4e0d\u662f\u5f88\u795e\u5947\uff0c\u6211\u4eec\u7ee7\u627f\u7684ServiceImpl\u4f9d\u65e7\u5b9e\u73b0\u4e86BaseMapper\u63a5\u53e3\u548cIservice\u63a5\u53e3\uff0c\u8fd9\u5c31\u611f\u89c9\u6709\u70b9\u5570\u55e6\u4e86\uff0c\u660e\u660e\u6211\u4eec\u5355\u72ec\u5199\u4e86RestDeptMapper\uff0c\u5e76\u4e14\u7ee7\u627f\u4e86BaseMapper\uff0c\u73b0\u5728ServiceImpl\u8fd8\u662f\u5b9e\u73b0\u4e86BaseMapper\uff0c\u90a3\u6211\u76f4\u63a5\u4e00\u4e2aService\u7528\u4e0b\u6765\u4e0d\u5c31\u884c\u4e86\uff0c\u521b\u5efa\u4e24\u5957\u7c7b\uff0c\u529f\u80fd\u76f8\u4f3c\uff0c\u8fd8\u5bb9\u6613\u6df7\u4e71\uff0c\u4ee3\u7801\u7ed3\u6784\u5197\u4f59\u3002<\/h4>\n<h4>\u672c\u7740\u201c\u5b58\u5728\u5373\u5408\u7406\u201d\u7684\u7406\u5ff5\uff0c\u6211\u4eec\u5bf9\u6bd4\u4e00\u4e0b\u4e24\u4e2a\u63a5\u53e3\u7684\u65b9\u6cd5\u3002<\/h4>\n<p><img decoding=\"async\" src=\"http:\/\/cos.rain1024.com\/markdown\/image-20200319141921170.png\" alt=\"image-20200319141921170\" \/><\/p>\n<h4>\u679c\u7136\uff0cService\u7b80\u76f4\u662fBaseMapper\u7684\u5927\u6269\u5145\uff0c\u4e0d\u4f46\u5305\u542b\u4e86\u6240\u6709\u57fa\u672c\u65b9\u6cd5\uff0c\u8fd8\u52a0\u5165\u4e86\u5f88\u591a\u6279\u5904\u7406\u529f\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u4e00\u4e0b\u5b98\u7f51\u5bf9\u8fd9\u4e24\u79cd\u63a5\u53e3\u7684\u8bf4\u660e\u3002<\/h4>\n<p>\u5b98\u7f51\u94fe\u63a5\uff1ahttps:\/\/mp.baomidou.com\/guide\/crud-interface.html#remove<\/p>\n<h2>Service CRUD \u63a5\u53e3<\/h2>\n<p>\u8bf4\u660e:<\/p>\n<ul>\n<li>\u901a\u7528 Service CRUD \u5c01\u88c5<a href=\"https:\/\/gitee.com\/baomidou\/mybatis-plus\/blob\/3.0\/mybatis-plus-extension\/src\/main\/java\/com\/baomidou\/mybatisplus\/extension\/service\/IService.java\">IService<\/a>\u63a5\u53e3\uff0c\u8fdb\u4e00\u6b65\u5c01\u88c5 CRUD \u91c7\u7528 <code>get \u67e5\u8be2\u5355\u884c<\/code> <code>remove \u5220\u9664<\/code> <code>list \u67e5\u8be2\u96c6\u5408<\/code> <code>page \u5206\u9875<\/code> \u524d\u7f00\u547d\u540d\u65b9\u5f0f\u533a\u5206 <code>Mapper<\/code> \u5c42\u907f\u514d\u6df7\u6dc6\uff0c<\/li>\n<li>\u6cdb\u578b <code>T<\/code> \u4e3a\u4efb\u610f\u5b9e\u4f53\u5bf9\u8c61<\/li>\n<li>\u5efa\u8bae\u5982\u679c\u5b58\u5728\u81ea\u5b9a\u4e49\u901a\u7528 Service \u65b9\u6cd5\u7684\u53ef\u80fd\uff0c\u8bf7\u521b\u5efa\u81ea\u5df1\u7684 <code>IBaseService<\/code> \u7ee7\u627f <code>Mybatis-Plus<\/code> \u63d0\u4f9b\u7684\u57fa\u7c7b<\/li>\n<li>\u5bf9\u8c61 <code>Wrapper<\/code> \u4e3a <a href=\"https:\/\/mp.baomidou.com\/guide\/wrapper.html\">\u6761\u4ef6\u6784\u9020\u5668<\/a><\/li>\n<\/ul>\n<h2>Mapper CRUD \u63a5\u53e3<\/h2>\n<p>\u8bf4\u660e:<\/p>\n<ul>\n<li>\u901a\u7528 CRUD \u5c01\u88c5<a href=\"https:\/\/gitee.com\/baomidou\/mybatis-plus\/blob\/3.0\/mybatis-plus-core\/src\/main\/java\/com\/baomidou\/mybatisplus\/core\/mapper\/BaseMapper.java\">BaseMapper<\/a>\u63a5\u53e3\uff0c\u4e3a <code>Mybatis-Plus<\/code> \u542f\u52a8\u65f6\u81ea\u52a8\u89e3\u6790\u5b9e\u4f53\u8868\u5173\u7cfb\u6620\u5c04\u8f6c\u6362\u4e3a <code>Mybatis<\/code> \u5185\u90e8\u5bf9\u8c61\u6ce8\u5165\u5bb9\u5668<\/li>\n<li>\u6cdb\u578b <code>T<\/code> \u4e3a\u4efb\u610f\u5b9e\u4f53\u5bf9\u8c61<\/li>\n<li>\u53c2\u6570 <code>Serializable<\/code> \u4e3a\u4efb\u610f\u7c7b\u578b\u4e3b\u952e <code>Mybatis-Plus<\/code> \u4e0d\u63a8\u8350\u4f7f\u7528\u590d\u5408\u4e3b\u952e\u7ea6\u5b9a\u6bcf\u4e00\u5f20\u8868\u90fd\u6709\u81ea\u5df1\u7684\u552f\u4e00 <code>id<\/code> \u4e3b\u952e<\/li>\n<li>\u5bf9\u8c61 <code>Wrapper<\/code> \u4e3a <a href=\"https:\/\/mp.baomidou.com\/guide\/wrapper.html\">\u6761\u4ef6\u6784\u9020\u5668<\/a><\/li>\n<\/ul>\n<h4>\u6700\u540e\u672c\u6587\u8fd8\u662f\u6bd4\u8f83\u6c34\u7684\uff0c\u53ea\u662f\u7b80\u5355\u7684\u770b\u4e86\u4e00\u4e0b\u7ed3\u6784\u800c\u5df2\uff0c\u6ca1\u6709\u592a\u591a\u7684\u6df1\u5165\uff0c\u603b\u7ed3\u4e00\u4e0b\uff0c\u4ee5\u6211\u5e73\u65f6\u7c98\u8d34\u590d\u5236\u7684\u7ecf\u9a8c\u6765\u770b\uff0cService\u867d\u7136\u52a0\u5165\u4e86\u6570\u636e\u5e93\u7684\u64cd\u4f5c\uff0c\u4f46\u8fd8\u662f\u4ee5\u4e1a\u52a1\u529f\u80fd\u4e3a\u4e3b\uff0c\u800c\u66f4\u52a0\u590d\u6742\u7684SQL\u67e5\u8be2\uff0c\u8fd8\u662f\u8981\u9760Mapper\u5bf9\u5e94\u7684XML\u6587\u4ef6\u91cc\u53bb\u7f16\u5199SQL\u8bed\u53e5\u3002<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u540e\u7aef\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u6709\u7528\u5230mybatis-plus\uff0c\u80af\u5b9a\u4f1a\u53d1\u73b0\u5728\u5176\u5185\u90e8\u5b58\u5728\u7740\u4e24\u79cd\u6570\u636e\u5e93\u64cd\u4f5c\u63a5\u53e3\uff0cIservice\u548cBaseMapper\uff0c\u5982\u679c\u53ea\u662f\u7528\u589e\u5220\u6539\u67e5\u4f1a\u53d1\u73b0\u4e24\u8005\u7684\u529f\u80fd\u662f\u4e00\u81f4\u7684\uff0c\u9664\u4e86\u65b9\u6cd5\u540d\u79f0\u6709\u6240\u4e0d\u540c\uff0c\u5176\u4ed6\u7684\u57fa\u672c\u76f8\u4f3c\u3002\u5bf9\u6b64\uff0c\u6211\u9887\u4e3a\u597d\u5947\uff0c\u4fbf\u6253\u5f00\u4e24\u4e2a\u63a5\u53e3\u7684\u6e90\u7801\u8fdb\u884c\u5bf9\u6bd4\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-1106","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/comments?post=1106"}],"version-history":[{"count":1,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1106\/revisions"}],"predecessor-version":[{"id":1361,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/posts\/1106\/revisions\/1361"}],"wp:attachment":[{"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/media?parent=1106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/categories?post=1106"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/rain1024.com\/index.php\/wp-json\/wp\/v2\/tags?post=1106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}