{"id":7746,"date":"2024-11-14T08:23:59","date_gmt":"2024-11-14T00:23:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7746\/"},"modified":"2024-11-14T08:23:59","modified_gmt":"2024-11-14T00:23:59","slug":"mybatis-%e6%b5%8b%e8%af%95%e7%b1%bb%e4%b8%ad%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%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3non-static-method-list-c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7746\/","title":{"rendered":"Mybatis \u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\u201cNon-static method &#8216;list()&#8217; cannot be referenced from a static context\u201d\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173121643467231.jpg\" class=\"aligncenter\" title=\"Mybatis \u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\u201cNon-static method &#8216;list()&#8217; cannot be referenced from a static context\u201d\uff1f\u63d2\u56fe\" alt=\"Mybatis \u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\u201cNon-static method &#8216;list()&#8217; cannot be referenced from a static context\u201d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 idea \u7684 mybatis \u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u65f6\u62a5\u9519<\/strong><\/p>\n<p>\u5728\u7f16\u5199 mybatis \u6d4b\u8bd5\u7c7b\u65f6\uff0c\u8c03\u7528\u7528\u6237\u6620\u5c04\u5668\u63a5\u53e3 usermapper \u4e2d\u7684 list \u65b9\u6cd5\u5374\u9047\u5230\u4e86\u62a5\u9519\uff1a&#8221;non-static method &#8216;list()&#8217; cannot be referenced from a static context&#8221;\u3002<\/p>\n<p><strong>\u539f\u56e0\u5206\u6790<\/strong><\/p>\n<p>\u51fa\u73b0\u6b64\u62a5\u9519\u7684\u539f\u56e0\u662f\uff0c\u5728\u6d4b\u8bd5\u7c7b\u4e2d\uff0c\u7f16\u8bd1\u5668\u65e0\u6cd5\u8bc6\u522b\u63a5\u53e3\u53d8\u91cf usermapper\u3002\u5728 java \u4e2d\uff0c\u63a5\u53e3\u53d8\u91cf\u5fc5\u987b\u5148\u88ab\u5b9e\u4f8b\u5316\u624d\u80fd\u4f7f\u7528\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u5b9e\u4f8b\u5316 usermapper \u63a5\u53e3\u3002\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<ol>\n<li>\n<p>\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u521b\u5efa usermapper \u63a5\u53e3\u7684\u5b9e\u4f8b\uff1a<\/p>\n<pre>private usermapper usermapper; \/\/ \u58f0\u660e\u4e00\u4e2a usermapper \u5b9e\u4f8b\u53d8\u91cf<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p>\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u6ce8\u5165 usermapper \u5b9e\u4f8b\uff1a<\/p>\n<pre>@autowired\npublic void setusermapper(usermapper usermapper) {\n this.usermapper = usermapper;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<li>\n<p>\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u8c03\u7528 list \u65b9\u6cd5\uff1a<\/p>\n<pre>List&lt;User&gt; users = userMapper.list(); \/\/ \u8c03\u7528 list \u65b9\u6cd5<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236  <\/li>\n<\/ol>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\u5b9e\u4f8b\u5316 usermapper \u63a5\u53e3\uff0c\u7f16\u8bd1\u5668\u5c31\u53ef\u4ee5\u8bc6\u522b\u63a5\u53e3\u53d8\u91cf\uff0c\u4ece\u800c\u89e3\u51b3\u62a5\u9519\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMybatis \u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u62a5\u9519\uff1a\u5982\u4f55\u89e3\u51b3\u201cNon-static method &#8216;list()&#8217; cannot be referenced from a static context\u201d\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 idea \u7684 mybatis \u6d4b\u8bd5\u7c7b\u4e2d\u8c03\u7528\u63a5\u53e3\u65b9\u6cd5\u65f6\u62a5\u9519 \u5728\u7f16\u5199 mybatis \u6d4b\u8bd5\u7c7b\u65f6\uff0c\u8c03\u7528\u7528\u6237\u6620\u5c04\u5668\u63a5\u53e3 usermapper \u4e2d\u7684 list \u65b9\u6cd5\u5374\u9047\u5230\u4e86\u62a5\u9519\uff1a&#8221;non-static method &#8216;list()&#8217; cannot be referenced from a static context&#8221;\u3002 \u539f\u56e0\u5206\u6790 \u51fa\u73b0\u6b64\u62a5\u9519\u7684\u539f\u56e0\u662f\uff0c\u5728\u6d4b\u8bd5\u7c7b\u4e2d\uff0c\u7f16\u8bd1\u5668\u65e0\u6cd5\u8bc6\u522b\u63a5\u53e3\u53d8\u91cf usermapper\u3002\u5728 java \u4e2d\uff0c\u63a5\u53e3\u53d8\u91cf\u5fc5\u987b\u5148\u88ab\u5b9e\u4f8b\u5316\u624d\u80fd\u4f7f\u7528\u3002 \u89e3\u51b3\u65b9\u6cd5 \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5728\u6d4b\u8bd5\u7c7b\u4e2d\u5b9e\u4f8b\u5316 usermapper \u63a5\u53e3\u3002\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a \u5728\u6d4b\u8bd5\u7c7b\u4e2d\u521b\u5efa usermapper \u63a5\u53e3\u7684\u5b9e\u4f8b\uff1a private usermapper usermapper; \/\/ \u58f0\u660e\u4e00\u4e2a usermapper \u5b9e\u4f8b\u53d8\u91cf \u767b\u5f55\u540e\u590d\u5236 \u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u6ce8\u5165 usermapper \u5b9e\u4f8b\uff1a @autowired public void setusermapper(usermapper usermapper) { this.usermapper = usermapper; } \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/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-7746","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7746","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=7746"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7746\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}