{"id":27116,"date":"2024-11-24T15:57:36","date_gmt":"2024-11-24T07:57:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27116\/"},"modified":"2024-11-24T15:57:36","modified_gmt":"2024-11-24T07:57:36","slug":"mybatis-%e6%b5%8b%e8%af%95%e7%b1%bb%e8%b0%83%e7%94%a8%e6%8e%a5%e5%8f%a3%e6%96%b9%e6%b3%95%e6%8a%a5%e9%94%99%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88%e6%97%a0%e6%b3%95%e4%bb%8e%e9%9d%99%e6%80%81%e4%b8%8a-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27116\/","title":{"rendered":"Mybatis \u6d4b\u8bd5\u7c7b\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u4e3a\u4ec0\u4e48\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173116296471969.jpg\" class=\"aligncenter\" title=\"Mybatis \u6d4b\u8bd5\u7c7b\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u4e3a\u4ec0\u4e48\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\uff1f\u63d2\u56fe\" alt=\"Mybatis \u6d4b\u8bd5\u7c7b\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u4e3a\u4ec0\u4e48\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>idea mybatis \u6d4b\u8bd5\u7c7b\u65e0\u6cd5\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u7684\u539f\u56e0<\/h2>\n<p>\u5728\u4f7f\u7528 idea \u8fdb\u884c mybatis \u6d4b\u8bd5\u65f6\uff0c\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u51fa\u73b0\u62a5\u9519\u7684\u60c5\u51b5\uff0c\u539f\u56e0\u53ef\u80fd\u662f\uff1a<\/p>\n<h3>\u9519\u8bef\u63d0\u793a<\/h3>\n<p>\u5f53\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528 usermapper \u63a5\u53e3\u7684 list() \u65b9\u6cd5\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0 &#8220;non-static method &#8216;list()&#8217; cannot be referenced from a static context&#8221; \u9519\u8bef\u3002<\/p>\n<h3>\u539f\u56e0\u5206\u6790<\/h3>\n<p>\u8be5\u9519\u8bef\u63d0\u793a\u8868\u660e\uff0c\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\u3002\u5728\u6d4b\u8bd5\u7c7b\u4e2d\uff0cmn() \u65b9\u6cd5\u662f\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\uff0c\u800c\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u662f\u975e\u9759\u6001\u7684\uff0c\u5bfc\u81f4\u4e86\u51b2\u7a81\u3002<\/p>\n<h3>\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5c06 usermapper \u63a5\u53e3\u7684 list() \u65b9\u6cd5\u58f0\u660e\u4e3a\u9759\u6001\u7684\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>public interface UserMapper {\n    static List&lt;User&gt; list() {\n        \/\/ ...\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u8c03\u7528\uff0c\u4ece\u800c\u89e3\u51b3\u9519\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMybatis \u6d4b\u8bd5\u7c7b\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>idea mybatis \u6d4b\u8bd5\u7c7b\u65e0\u6cd5\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u7684\u539f\u56e0 \u5728\u4f7f\u7528 idea \u8fdb\u884c mybatis \u6d4b\u8bd5\u65f6\uff0c\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u51fa\u73b0\u62a5\u9519\u7684\u60c5\u51b5\uff0c\u539f\u56e0\u53ef\u80fd\u662f\uff1a \u9519\u8bef\u63d0\u793a \u5f53\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528 usermapper \u63a5\u53e3\u7684 list() \u65b9\u6cd5\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0 &#8220;non-static method &#8216;list()&#8217; cannot be referenced from a static context&#8221; \u9519\u8bef\u3002 \u539f\u56e0\u5206\u6790 \u8be5\u9519\u8bef\u63d0\u793a\u8868\u660e\uff0c\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\u3002\u5728\u6d4b\u8bd5\u7c7b\u4e2d\uff0cmn() \u65b9\u6cd5\u662f\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\uff0c\u800c\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u662f\u975e\u9759\u6001\u7684\uff0c\u5bfc\u81f4\u4e86\u51b2\u7a81\u3002 \u89e3\u51b3\u65b9\u6cd5 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5c06 usermapper \u63a5\u53e3\u7684 list() \u65b9\u6cd5\u58f0\u660e\u4e3a\u9759\u6001\u7684\u3002\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a public interface UserMapper { static List&lt;User&gt; list() { \/\/ &#8230; } } \u767b\u5f55\u540e\u590d\u5236 \u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u8c03\u7528\uff0c\u4ece\u800c\u89e3\u51b3\u9519\u8bef\u3002 \u4ee5\u4e0a\u5c31\u662fMybatis \u6d4b\u8bd5\u7c7b\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u65e0\u6cd5\u4ece\u9759\u6001\u4e0a\u4e0b\u6587\u4e2d\u5f15\u7528\u975e\u9759\u6001\u65b9\u6cd5\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27116","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27116"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27116\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}