{"id":203769,"date":"2025-05-22T15:11:26","date_gmt":"2025-05-22T07:11:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203769\/"},"modified":"2025-05-22T15:11:26","modified_gmt":"2025-05-22T07:11:26","slug":"%e9%80%9a%e8%bf%87%e8%a7%a3%e5%86%b3%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86%e9%97%ae%e9%a2%98%e6%9d%a5%e5%a2%9e%e5%bc%ba%e6%82%a8%e7%9a%84-spring-boot-%e6%8a%80%e8%83%bd%ef%bc%9a%e4%b8%ba-usernotfoundexc","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203769\/","title":{"rendered":"\u901a\u8fc7\u89e3\u51b3\u5f02\u5e38\u5904\u7406\u95ee\u9898\u6765\u589e\u5f3a\u60a8\u7684 Spring Boot \u6280\u80fd\uff1a\u4e3a UserNotFoundException \u5b9e\u73b0\u5168\u5c40\u5904\u7406\u7a0b\u5e8f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u901a\u8fc7\u89e3\u51b3\u5f02\u5e38\u5904\u7406\u95ee\u9898\u6765\u589e\u5f3a\u60a8\u7684 Spring Boot \u6280\u80fd\uff1a\u4e3a UserNotFoundException \u5b9e\u73b0\u5168\u5c40\u5904\u7406\u7a0b\u5e8f<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u79ef\u7d2f\u77e5\u8bc6\uff0c\u80dc\u8fc7\u79ef\u84c4\u91d1\u94f6\uff01\u6bd5\u7adf\u5728\u6587\u7ae0\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u5f80\u5f80\u90fd\u662f\u4e00\u4e9b\u7ec6\u8282\u77e5\u8bc6\u70b9\u8fd8\u6ca1\u6709\u638c\u63e1\u597d\u800c\u5bfc\u81f4\u7684\uff0c\u56e0\u6b64\u57fa\u7840\u77e5\u8bc6\u70b9\u7684\u79ef\u7d2f\u662f\u5f88\u91cd\u8981\u7684\u3002\u4e0b\u9762\u672c\u6587\u300a\u901a\u8fc7\u89e3\u51b3\u5f02\u5e38\u5904\u7406\u95ee\u9898\u6765\u589e\u5f3a\u60a8\u7684 Spring Boot \u6280\u80fd\uff1a\u4e3a UserNotFoundException \u5b9e\u73b0\u5168\u5c40\u5904\u7406\u7a0b\u5e8f\u300b\uff0c\u5c31\u5e26\u5927\u5bb6\u8bb2\u89e3\u4e00\u4e0b\u77e5\u8bc6\u70b9\uff0c\u82e5\u662f\u4f60\u5bf9\u672c\u6587\u611f\u5174\u8da3\uff0c\u6216\u8005\u662f\u60f3\u641e\u61c2\u5176\u4e2d\u67d0\u4e2a\u77e5\u8bc6\u70b9\uff0c\u5c31\u8bf7\u4f60\u7ee7\u7eed\u5f80\u4e0b\u770b\u5427~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/1732325553674130b1aaf06.jpg\" class=\"aligncenter\"><\/p>\n<hr>\n<h2> \u6982\u8ff0 <\/h2>\n<p>\u6b64\u5b9e\u73b0\u901a\u8fc7\u5b9a\u4e49\u81ea\u5b9a\u4e49\u5f02\u5e38 usernotfoundexception \u5e76\u5b9e\u73b0\u5168\u5c40\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u6765\u6709\u6548\u7ba1\u7406\u6b64\u5f02\u5e38\uff0c\u589e\u5f3a\u4e86 journal rest api \u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5f02\u5e38\u5904\u7406\u673a\u5236\u3002\u76ee\u6807\u662f\u96c6\u4e2d\u5f02\u5e38\u5904\u7406\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<p>\u8981\u53d1\u5e03<\/p>\n<hr>\n<h2> \u4efb\u52a1 <\/h2>\n<h3> 1.\u5b9a\u4e49usernotfoundexception <\/h3>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a usernotfoundexception \u7684\u81ea\u5b9a\u4e49\u5f02\u5e38\u7c7b\u3002<\/p>\n<h3> 2. \u5b9e\u73b0\u5168\u5c40\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f <\/h3>\n<p>\u5b9e\u73b0\u5168\u5c40\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\u6765\u7ba1\u7406 usernotfoundexception\u3002<\/p>\n<h3> 3. \u91cd\u6784\u73b0\u6709\u4ee3\u7801 <\/h3>\n<p>\u91cd\u6784\u73b0\u6709\u63a7\u5236\u5668\u4ee3\u7801\u4ee5\u5220\u9664 usernotfoundexception \u7684\u672c\u5730\u5904\u7406\u3002<\/p>\n<hr>\n<h2> \u5982\u4f55\u8d21\u732e <\/h2>\n<ol>\n<li> <strong>\u5206\u53c9\u5b58\u50a8\u5e93\uff1a<\/strong> journal-rest-api <\/li>\n<li>\n<p><strong>\u514b\u9686\u5b58\u50a8\u5e93\uff1a<\/strong><\/p>\n<pre>git clone https:\/\/github.com\/yourusername\/journal-rest-api.git\ncd journal-rest-api\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u5206\u652f\uff1a<\/strong><\/p>\n<pre>git checkout -b enhance-exception-handling\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u8fdb\u884c\u66f4\u6539\u5e76\u63d0\u4ea4\uff1a<\/strong><\/p>\n<pre>git add .\ngit commit -m \"enhance exception handling and implement global exception handler for usernotfoundexception\"\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u63a8\u9001\u5230\u5206\u652f\uff1a<\/strong><\/p>\n<pre>git push origin enhance-exception-handling\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa\u62c9\u53d6\u8bf7\u6c42\uff1a<\/strong>\u8f6c\u5230 github \u4e0a\u7684\u5b58\u50a8\u5e93\u5e76\u521b\u5efa\u62c9\u53d6\u8bf7\u6c42\u3002<\/p>\n<\/li>\n<\/ol>\n<hr>\n<h2> \u7ed3\u8bba <\/h2>\n<p>\u901a\u8fc7\u589e\u5f3a\u5f02\u5e38\u5904\u7406\u673a\u5236\u5e76\u5b9e\u73b0\u5168\u5c40\u5f02\u5e38\u5904\u7406\u7a0b\u5e8f\uff0c\u6211\u4eec\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u5e93\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u4e00\u81f4\u6027\u3002\u6211\u6b22\u8fce\u793e\u533a\u7684\u8d21\u732e\u6765\u5e2e\u52a9\u6211\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<hr>\n<p>\u5982\u679c\u60a8\u6709\u4efb\u4f55\u7591\u95ee\u6216\u9700\u8981\u8fdb\u4e00\u6b65\u5e2e\u52a9\uff0c\u8bf7\u968f\u65f6\u4e0e\u6211\u4eec\u8054\u7cfb\u3002\u5feb\u4e50\u7f16\u7801\uff01<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u901a\u8fc7\u89e3\u51b3\u5f02\u5e38\u5904\u7406\u95ee\u9898\u6765\u589e\u5f3a\u60a8\u7684 Spring Boot \u6280\u80fd\uff1a\u4e3a UserNotFoundException \u5b9e\u73b0\u5168\u5c40\u5904\u7406\u7a0b\u5e8f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u89e3\u51b3\u5f02\u5e38\u5904\u7406\u95ee\u9898\u6765\u589e\u5f3a\u60a8\u7684 &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203769","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203769"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203769\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}