{"id":197702,"date":"2020-11-03T17:36:11","date_gmt":"2020-11-03T09:36:11","guid":{"rendered":"http:\/\/4563.org\/?p=197702"},"modified":"2020-11-03T17:36:11","modified_gmt":"2020-11-03T09:36:11","slug":"%e5%85%b3%e4%ba%8e%e4%b8%9a%e5%8a%a1%e5%bc%82%e5%b8%b8%e7%9a%84%e5%a4%84%e7%90%86%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=197702","title":{"rendered":"\u5173\u4e8e\u4e1a\u52a1\u5f02\u5e38\u7684\u5904\u7406\u65b9\u5f0f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5173\u4e8e\u4e1a\u52a1\u5f02\u5e38\u7684\u5904\u7406\u65b9\u5f0f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Dingjiangnan <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u65b0\u624b\u63d0\u95ee\uff1a\u201c\u5173\u4e8e\u4e1a\u52a1\u5f02\u5e38\u7684\u5904\u7406\u65b9\u5f0f\u201d\uff0c\u5728 V \u7ad9\u641c\u4e86\u4e00\u4e0b\u90fd\u662f\u5f88\u4e45\u4ee5\u524d\u7684\u65e7\u5e16\u5b50\uff0c\u6240\u4ee5\u5f00\u4e2a\u65b0\u5e16\u63d0\u95ee<\/p>\n<p>\u4e4b\u524d\u7684\u516c\u53f8\u662f\u5b8c\u5168\u4e0d\u7528\u5f02\u5e38\uff0c\u6bd4\u5982\u7528\u6237\u540d\u4e0d\u6b63\u786e\u7684\u5904\u7406\uff1a<\/p>\n<pre><code> public void login(String username,String password){        User user = db.getUsername(username);        if(user==null){           \/\/UnifyResponse \u662f\u7edf\u4e00\u54cd\u5e94\u5b9e\u4f53\u7c7b\uff0c\u53c2\u6570 1:code\uff0c\u53c2\u6570 2:message       return UnifyResponse.FAIL(400,\"\u7528\u6237\u4e0d\u5b58\u5728\");     }      } <\/code><\/pre>\n<p>\u8fd4\u56de\u7ed9\u524d\u7aef\u7684\u683c\u5f0f\uff1a<\/p>\n<pre><code>http status : 200  {  code: 400,     message: \"\u7528\u6237\u540d\u4e0d\u6b63\u786e\" } <\/code><\/pre>\n<p>\u73b0\u5728\u8fd9\u5bb6\u516c\u53f8\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code> public void login(String username,String password){        User user = db.getUsername(username);        if(user==null){           \/\/UnifyResponse \u662f\u7edf\u4e00\u54cd\u5e94\u5b9e\u4f53\u7c7b\uff0c\u53c2\u6570 1:code\uff0c\u53c2\u6570 2:message               throw new NotFoundException(400,\"\u7528\u6237\u540d\u4e0d\u6b63\u786e\")     }      } <\/code><\/pre>\n<p>\u8fd4\u56de\u7ed9\u524d\u7aef\u7684\u683c\u5f0f\uff1a<\/p>\n<pre><code>http status : 404  {  code: 400,     message: \"\u7528\u6237\u540d\u4e0d\u6b63\u786e\"      } <\/code><\/pre>\n<p>\u4e24\u4e2a\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>\u5173\u4e8e\u4e1a\u52a1\u7684\u5904\u7406\uff0c\u662f\u8fd9\u5c4a return\uff0c\u8fd8\u662f throw \u5f02\u5e38\u4e4b\u540e\uff0c\u5168\u5c40\u8fdb\u884c\u6355\u83b7\u518d return \uff1f<\/li>\n<li>\u5173\u4e8e http status\uff0c\u662f\u65e0\u8bba\u662f\u5426\u6210\u529f\u90fd\u8fd4\u56de 200\uff0c\u8fd8\u662f\u9075\u5faa restful \u89c4\u8303\uff0c404 \u4e0d\u5b58\u5728\uff0c403 \u65e0\u6743\u9650\uff1f<\/li>\n<\/ul>\n<p>\u5927\u5bb6\u8bf4\u8bf4\u54ea\u79cd\u5904\u7406\u66f4\u597d\uff1f\u524d\u7aef\u540c\u5b66\u80fd\u5426\u63a5\u53d7 restful \u7684 http status \u89c4\u8303<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>14<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4191839\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Dingjiangnan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u5c4a -&gt; \u76f4\u63a5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191840\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cabing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             1 \u5b9a\u4e49\u7edf\u4e00\u81ea\u6709\u7684\u72b6\u6001\u7801<br \/>2 \u76f4\u63a5\u8fd4\u56de\u7ed3\u679c\u5bf9\u8c61\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191841\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bl <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u5df1\u5f02\u5e38\u7c7b\uff0c\u81ea\u5b9a\u4e49 ErrorCode \u3002\u4e0d\u5728\u4e1a\u52a1\u4ee3\u7801\u91cc\u9762\u7f16\u5199\u5177\u4f53\u7684\u5f02\u5e38\u4fe1\u606f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191842\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imdong <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u8fd1\u5230\u65b0\u516c\u53f8\uff0c\u5e26\u65b0\u9879\u76ee\uff0c\u6211\u8ba1\u5212\u5168\u7a0b\u7528\u5f02\u5e38\u4e86\u3002<\/p>\n<p>\u5982\u679c\u7528 return \u5d4c\u5957\u591a\u5c42\u7684\u4ee3\u7801\uff0c\u6bcf\u4e00\u5c42\u90fd\u8981\u5224\u65ad + return \u592a\u8d39\u4e8b\u4e86\u3002<\/p>\n<p>\u73b0\u5728\u7528\u5f02\u5e38\uff0c\u54ea\u91cc\u51fa\u9519\u54ea\u91cc\u629b\uff0c\u5916\u9762\u518d\u4e5f\u4e0d\u9700\u8981\u7ba1\u8fd9\u4e9b\u4e86\u3002<\/p>\n<p>\u8fd8\u6ca1\u5f00\u59cb\u505a\uff0c\u672a\u77e5\u53ef\u80fd\u51fa\u73b0\u7684\u5751\uff0c\u5982\u679c\u9700\u8981\u5305\u88c5\uff0c\u5c31 try \u6355\u83b7\u4e00\u4e0b\u518d\u629b\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191843\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dustinth <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u754c\u9650\u786e\u5b9e\u6bd4\u8f83\u6a21\u7cca, \u56e0\u4e3a\u4e0d\u540c\u7684\u7cfb\u7edf part \u4e4b\u95f4, \u5bf9\u4e8e\u5f02\u5e38\u662f\u6709\u4e0d\u540c\u7684\u7406\u89e3\u7684: \u6bd4\u5982\u8981\u5b9e\u73b0\u4e00\u4e2a Map \u7684 API, \u5982\u679c get \u4e00\u4e2a\u4e0d\u5b58\u5728\u7684 key \u662f\u8fd4\u56de\u7a7a\u503c\u8fd8\u662f throw exception \u5462? \u7ad9\u5728 API \u5b9e\u73b0\u65b9, \u4ed6\u53ef\u80fd\u503e\u5411\u4e8e\u628a\u8fd9\u4e2a\u5f53\u505a\u5f02\u5e38; \u800c\u7ad9\u5728 API \u8c03\u7528\u65b9\u5219\u503e\u5411\u4e8e\u8fd4\u56de\u7a7a\u503c, \u56e0\u4e3a\u8fd9\u6837\u53ef\u4ee5\u7528\u6bd4\u8f83\u8f7b\u91cf\u7684\u65b9\u5f0f\u5904\u7406\u8fd9\u6837\u7684&#8221;\u5f02\u5e38&#8221;\u903b\u8f91\u5206\u652f.<\/p>\n<p>\u603b\u7ed3\u4e00\u4e2a\u4e0d\u592a\u5b9e\u7528\u7684\u5b9a\u4e49: &#8220;\u4e0d\u8981\u7528\u5f02\u5e38\u6765\u63a7\u5236\u4e3b\u4e1a\u52a1\u903b\u8f91\u5206\u652f&#8221;. \u8bf4\u4e0d\u592a\u5b9e\u7528\u662f\u56e0\u4e3a, \u4e0d\u540c\u4eba\u5bf9\u4ec0\u4e48\u662f&#8221;\u4e3b\u4e1a\u52a1\u903b\u8f91&#8221;\u7684\u7406\u89e3\u662f\u4e0d\u540c\u7684.<\/p>\n<p>LZ \u4e3e\u5f97\u4f8b\u5b50\u5c31\u6bd4\u8f83\u5178\u578b, \u56e0\u4e3a\u65e2\u53ef\u4ee5\u628a UserNotFound \u5f53\u505a\u4e1a\u52a1\u903b\u8f91\u7684\u4e00\u90e8\u5206(\u548c\u5176\u4ed6\u7c7b\u578b\u7684\u5f02\u5e38, \u6bd4\u5982\u7f51\u7edc\u9519\u8bef,\u670d\u52a1\u5668\u9519\u8bef\u7b49\u8fd8\u662f\u6709\u4e9b\u6982\u5ff5\u4e0a\u7684\u533a\u522b\u7684), \u4e5f\u53ef\u4ee5\u5f53\u505a\u5f02\u5e38. \u6211\u4e2a\u4eba\u89c9\u5f97, \u5982\u679c\u5bf9 500\/404\/400 \u7b49\u524d\u7aef\u5904\u7406\u903b\u8f91\u90fd\u662f\u4e00\u6837\u7684\u8bdd(\u6bd4\u5982\u5728\u67d0\u4e2a\u5730\u65b9\u663e\u793a warning message),\u90a3\u4e48\u8fd4\u56de\u5f02\u5e38\u6bd4\u8f83\u597d; \u5982\u679c\u5bf9 404 \u6709\u989d\u5916\u7684\u903b\u8f91\u4e1a\u52a1\u5904\u7406, \u5219\u8fd4\u56de\u7a7a\u503c\u66f4\u597d.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191844\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hdfg159 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             http status code + \u4e1a\u52a1\u9519\u8bef\u7801                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191845\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : EminemW <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imdong #4 \u81ea\u5b9a\u4e49\u5f02\u5e38\u4e0d\u4e5f\u8981\u5148\u5224\u65ad\u518d\u629b\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191846\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fewok <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4e2a\u4eba\u504f\u5411\u9519\u8bef\u7801\u3002\u4f46\u662f\u591a\u4eba\u5408\u4f5c\uff0c\u4e00\u5b9a\u8981\u7528\u5f02\u5e38\u3002<br \/>\u4e2a\u4eba\u6211\u80fd\u641e\u4e00\u4e2a\u8d2f\u7a7f\u6240\u6709\u65b9\u6cd5\u7684 BO \u57fa\u7c7b\uff0c\u81ea\u5df1\u9020\u6d41\u7a0b\u7f16\u6392\uff0c\u63a7\u5236\u4e0b\u4e00\u6b65\u8be5\u600e\u4e48\u505a\u3002\u540c\u6b65\u3001\u5f02\u6b65\u3001\u5e76\u53d1\u3001\u54cd\u5e94\u5f0f\u7b49\u7b49\u8f7b\u8f7b\u677e\u677e\u6d41\u7a0b\u8c03\u5ea6\u3002<br \/>\u800c\u961f\u53cb\u591a\u4e86\uff0c\u96be\u514d\u51fa\u73b0\u8c03\u5b8c\u4f60\u8fd4\u56de\u9519\u8bef\u7801\u7684\u65b9\u6cd5\uff0c\u8fd8\u7ee7\u7eed\u5411\u4e0b\u6267\u884c\u7684\u732a\u961f\u53cb\uff08\u5f3a\u5236\u6355\u83b7\u5f88\u91cd\u8981\uff09\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191847\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : raysmond <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u662f\u8fd9\u4e48\u5e72\u7684\uff1a<br \/>1 \u3001\u5168\u5c40 AOP \u6355\u83b7\u5f02\u5e38\uff0c\u4e1a\u52a1\u5f02\u5e38 base class \u5305\u542b\u6709\u4e1a\u52a1\u542b\u4e49\u7684 code \u3001message \u7b49\u5b57\u6bb5<br \/>2 \u3001\u5bf9\u5f02\u5e38\u5206\u7c7b\uff0c\u6839\u636e restful \u89c4\u8303\uff0c\u8fd4\u56de\u540c\u6b65\u7684 http status\uff0c\u4f8b\u5982\uff1a<br \/>400 \u53c2\u6570\u9519\u8bef\uff1b 401 \u65e0\u6743\u9650\uff1b 404 \u672a\u627e\u5230\uff1b 500 \u7cfb\u7edf\u9519\u8bef\uff0c\u5305\u62ec\u672a\u77e5\u5f02\u5e38\u7c7b\uff1b 429 \u9650\u6d41\uff1b\u7b49\u7b49<\/p>\n<p>http status \u4ee3\u8868\u7684\u63a5\u53e3\u72b6\u6001\uff0c\u5bf9\u5f02\u5e38\u5206\u5927\u7c7b\uff1b\u800c body \u91cc\u7684 code\uff0c\u4ee3\u8868\u7684\u662f\u5177\u6709\u4e1a\u52a1\u542b\u4e49\u7684\u72b6\u6001\uff0c\u6bd4\u5982\u7528\u6237\u88ab\u7981\u7528 10025 \u3001\u7528\u6237\u767b\u5f55\u5f02\u5e38 10026 \u8fd9\u4e9b                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191848\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fewok <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5173\u4e8e http status\uff0crestful \u89c4\u8303\u53ea\u662f\u4e3a\u4e86\u7b80\u5316\u7406\u89e3\u96be\u5ea6\u800c\u589e\u52a0\u5b9e\u73b0\u590d\u6742\u5ea6\u800c\u5df2\uff0c\u610f\u4e49\u4e0d\u5927\uff0c\u53ef\u4ee5\u4e22\u5f03\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191849\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yogogo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u662f\u6df7\u5408\u4f7f\u7528\uff0c\u770b\u573a\u666f\uff01\u4e3b\u8981\u4e1a\u52a1\u5904\u7406\uff0c\u6bd4\u5982\u4e8b\u52a1\u5904\u7406\u7684\u65f6\u5019\u7528\u5f02\u5e38\u5904\u7406\uff0c\u5176\u4ed6\u5c31 return \uff01\u5f02\u5e38\u5904\u7406\u4f1a\u6d88\u8017\u6027\u80fd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191850\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xuanbg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             throw \u7684\u597d\u5904\u662f\u4e0d\u9700\u8981\u7ba1\u8fd4\u56de\u503c\uff0c\u8fd9\u5728\u65b9\u6cd5\u88ab\u5176\u4ed6\u65b9\u6cd5\u8c03\u7528\u65f6\u5f88\u6709\u4f18\u52bf\u3002\u88ab\u8c03\u7528\u8005\u4e0d\u9700\u8981\u8fd4\u56de null \u4ec0\u4e48\u7684\uff0c\u8c03\u7528\u8005\u4e5f\u4e0d\u9700\u8981\u5199\u76f8\u5e94\u7684\u8c03\u7528\u9519\u8bef\u5224\u65ad\u903b\u8f91\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191851\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzl22100048 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             java \u5f53\u7136\u662f\u7528 problem-spring-web \u5e93\u89e3\u51b3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4191852\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : i4color <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5c11\u90e8\u5206\u7528 http status.\u5927\u90e8\u5206\u7528\u4e1a\u52a1 \u7684 \u72b6\u6001\u7801\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e\u4e1a\u52a1\u5f02\u5e38\u7684\u5904\u7406\u65b9\u5f0f \u8cc7\u6df1\u5927\u4f6c &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/197702"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=197702"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/197702\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=197702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=197702"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=197702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}