{"id":2189,"date":"2024-11-10T15:37:10","date_gmt":"2024-11-10T07:37:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2189\/"},"modified":"2024-11-10T15:37:10","modified_gmt":"2024-11-10T07:37:10","slug":"spring-boot-%e9%a1%b9%e7%9b%ae%e4%bd%bf%e7%94%a8-mybatis-%e6%97%b6%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-localhost8081-%e8%ae%bf%e9%97%ae%e6%ad%a3%e5%b8%b8%ef%bc%8c%e5%85%b6%e4%bb%96%e7%ab%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2189\/","title":{"rendered":"Spring Boot \u9879\u76ee\u4f7f\u7528 MyBatis \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 localhost:8081 \u8bbf\u95ee\u6b63\u5e38\uff0c\u5176\u4ed6\u7aef\u53e3\u8bbf\u95ee\u540e\u7aef\u629b\u51fa NullPointerException \u5f02\u5e38\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173068452313767.jpg\" class=\"aligncenter\" title=\"Spring Boot \u9879\u76ee\u4f7f\u7528 MyBatis \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 localhost:8081 \u8bbf\u95ee\u6b63\u5e38\uff0c\u5176\u4ed6\u7aef\u53e3\u8bbf\u95ee\u540e\u7aef\u629b\u51fa NullPointerException \u5f02\u5e38\uff1f\u63d2\u56fe\" alt=\"Spring Boot \u9879\u76ee\u4f7f\u7528 MyBatis \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 localhost:8081 \u8bbf\u95ee\u6b63\u5e38\uff0c\u5176\u4ed6\u7aef\u53e3\u8bbf\u95ee\u540e\u7aef\u629b\u51fa NullPointerException \u5f02\u5e38\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>localhost:8081\u8bbf\u95ee\u6b63\u5e38\uff0c\u5176\u4ed6\u7aef\u53e3\u8bbf\u95ee\u540e\u7aef\u629b\u51fanullpointerexception\u5f02\u5e38<\/strong><\/p>\n<p>\u73af\u5883\uff1aSpring Boot\u3001MyBatis<\/p>\n<p>\u62a5\u9519\u4fe1\u606f\uff1a<\/p>\n<pre>java.lang.NullPointerException: null<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u539f\u56e0\u5206\u6790\uff1a<\/p>\n<p>\u8be5\u5f02\u5e38\u901a\u5e38\u662f\u7531\u4e8e\u7a0b\u5e8f\u5c1d\u8bd5\u8bbf\u95ee\u4e00\u4e2a\u503c\u4e3a null \u7684\u5bf9\u8c61\u800c\u5f15\u8d77\u7684\u3002\u5728\u7ed9\u5b9a\u7684\u60c5\u51b5\u4e0b\uff0c\u5f02\u5e38\u53d1\u751f\u5728 UserController \u7684 login \u65b9\u6cd5\u4e2d\u3002\u7ecf\u8fc7\u4ed4\u7ec6\u68c0\u67e5\uff0c\u53d1\u73b0 UserController \u4e2d\u6ca1\u6709\u76f4\u63a5\u4f7f\u7528 null \u503c\uff0c\u56e0\u6b64\u53ef\u4ee5\u63a8\u65ad\u6ce8\u5165\u7684 mapper \u4e3a null \u624d\u5bfc\u81f4\u4e86\u5f02\u5e38\u7684\u629b\u51fa\u3002<\/p>\n<p>\u539f\u56e0\u53ef\u80fd\u662f\uff1a<\/p>\n<ul>\n<li>mapper \u63a5\u53e3\u672a\u88ab\u626b\u63cf\u5230\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5728\u542f\u52a8\u7c7b\u4e0a\u6dfb\u52a0 @MapperScan \u6ce8\u89e3\u6765\u626b\u63cf mapper \u5305\u4e0b\u7684\u63a5\u53e3\uff0c\u4f7f\u5176\u88ab Spring \u7ba1\u7406\u3002<\/li>\n<\/ul>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\u786e\u4fdd\u5728\u542f\u52a8\u7c7b\uff08\u4f8b\u5982 MyApplication\uff09\u4e0a\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u6ce8\u89e3\uff1a<\/p>\n<pre>@MapperScan(\"com.example.demo.mapper\")<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff0ccom.example.demo.mapper \u662f mapper \u63a5\u53e3\u6240\u5728\u7684\u5305\u3002\u6dfb\u52a0\u6b64\u6ce8\u89e3\u540e\uff0cSpring \u5c06\u626b\u63cf mapper \u5305\u5e76\u52a0\u8f7d\u6240\u6709\u63a5\u53e3\uff0c\u7136\u540e\u518d\u8fdb\u884c\u6ce8\u5165\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u81ea\u5b9a\u4e49\u7684 MybatisConfig \u914d\u7f6e\u7c7b\uff0c\u53ef\u4ee5\u5728\u8be5\u7c7b\u4e0a\u6dfb\u52a0 @MapperScan \u6ce8\u89e3\u6765\u66ff\u4ee3\u5728\u542f\u52a8\u7c7b\u4e0a\u7684\u6ce8\u89e3\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fSpring Boot \u9879\u76ee\u4f7f\u7528 MyBatis \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 localhost:8081 \u8bbf\u95ee\u6b63\u5e38\uff0c\u5176\u4ed6\u7aef\u53e3\u8bbf\u95ee\u540e\u7aef\u629b\u51fa NullPointerException \u5f02\u5e38\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>localhost:8081\u8bbf\u95ee\u6b63\u5e38\uff0c\u5176\u4ed6\u7aef\u53e3\u8bbf\u95ee\u540e\u7aef\u629b\u51fanullpointerexception\u5f02\u5e38 \u73af\u5883\uff1aSpring Boot\u3001MyBatis \u62a5\u9519\u4fe1\u606f\uff1a java.lang.NullPointerException: null \u767b\u5f55\u540e\u590d\u5236 \u539f\u56e0\u5206\u6790\uff1a \u8be5\u5f02\u5e38\u901a\u5e38\u662f\u7531\u4e8e\u7a0b\u5e8f\u5c1d\u8bd5\u8bbf\u95ee\u4e00\u4e2a\u503c\u4e3a null \u7684\u5bf9\u8c61\u800c\u5f15\u8d77\u7684\u3002\u5728\u7ed9\u5b9a\u7684\u60c5\u51b5\u4e0b\uff0c\u5f02\u5e38\u53d1\u751f\u5728 UserController \u7684 login \u65b9\u6cd5\u4e2d\u3002\u7ecf\u8fc7\u4ed4\u7ec6\u68c0\u67e5\uff0c\u53d1\u73b0 UserController \u4e2d\u6ca1\u6709\u76f4\u63a5\u4f7f\u7528 null \u503c\uff0c\u56e0\u6b64\u53ef\u4ee5\u63a8\u65ad\u6ce8\u5165\u7684 mapper \u4e3a null \u624d\u5bfc\u81f4\u4e86\u5f02\u5e38\u7684\u629b\u51fa\u3002 \u539f\u56e0\u53ef\u80fd\u662f\uff1a mapper \u63a5\u53e3\u672a\u88ab\u626b\u63cf\u5230\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5728\u542f\u52a8\u7c7b\u4e0a\u6dfb\u52a0 @MapperScan \u6ce8\u89e3\u6765\u626b\u63cf mapper \u5305\u4e0b\u7684\u63a5\u53e3\uff0c\u4f7f\u5176\u88ab Spring \u7ba1\u7406\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u786e\u4fdd\u5728\u542f\u52a8\u7c7b\uff08\u4f8b\u5982 MyApplication\uff09\u4e0a\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u6ce8\u89e3\uff1a @MapperScan(&#8220;com.example.demo.mapper&#8221;) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0ccom.example.demo.mapper \u662f mapper \u63a5\u53e3\u6240\u5728\u7684\u5305\u3002\u6dfb\u52a0\u6b64\u6ce8\u89e3\u540e\uff0cSpring \u5c06\u626b\u63cf mapper \u5305\u5e76\u52a0\u8f7d\u6240\u6709\u63a5\u53e3\uff0c\u7136\u540e\u518d\u8fdb\u884c\u6ce8\u5165\u3002 \u6ce8\u610f\uff1a \u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u81ea\u5b9a\u4e49\u7684 MybatisConfig \u914d\u7f6e\u7c7b\uff0c\u53ef\u4ee5\u5728\u8be5\u7c7b\u4e0a\u6dfb\u52a0 @MapperScan \u6ce8\u89e3\u6765\u66ff\u4ee3\u5728\u542f\u52a8\u7c7b\u4e0a\u7684\u6ce8\u89e3\u3002 \u4ee5\u4e0a\u5c31\u662fSpring Boot \u9879\u76ee\u4f7f\u7528 MyBatis \u65f6\uff0c\u5982\u4f55\u89e3\u51b3 [&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-2189","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2189","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=2189"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2189\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2189"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2189"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}