{"id":3483,"date":"2018-12-05T11:22:41","date_gmt":"2018-12-05T03:22:41","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3483"},"modified":"2018-12-05T11:22:41","modified_gmt":"2018-12-05T03:22:41","slug":"%e5%a6%82%e4%bd%95%e5%86%99%e5%87%ba%e5%81%a5%e5%a3%ae%e7%9a%84-java-%e4%bb%a3%e7%a0%81%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3483","title":{"rendered":"\u5982\u4f55\u5199\u51fa\u5065\u58ee\u7684 Java \u4ee3\u7801\uff01"},"content":{"rendered":"<p>\n\t\u5982\u4f55\u5199\u51fa\u5065\u58ee\u7684 Java \u4ee3\u7801\uff1f\u6211\u76f8\u4fe1\u8fd9\u662f\u5f88\u591a\u4eba\u90fd\u6709\u7684\u7591\u60d1\u6216\u8005\u60f3\u8981\u7684\u7b54\u6848\u3002\u4eca\u5929\u6211\u4eec\u62bd\u4e2a\u65f6\u95f4\u4e00\u8d77\u63a2\u8ba8\u4e00\u4e0b\uff01\n<\/p>\n<p>\n\t\u8bf4\u5b9e\u8bdd\uff0c\u770b\u5230\u8fd9\u4e2a\u95ee\u9898\u6211\u4e5f\u4e0d\u77e5\u9053\u5982\u4f55\u56de\u7b54\u4e3a\u597d\uff01\u6240\u4ee5\u6211\u4e5f\u9700\u8981\u7b54\u6848\uff01\n<\/p>\n<p>\n\t\u4e8e\u662f\u6211\u5c31\u53bb\u767e\u5ea6\uff0c\u8c37\u6b4c\u3002\u5404\u79cd\u641c\u7d22\uff0c\u5bfb\u627e\u5404\u79cd\u7f16\u7a0b\u6280\u5de7\u548c\u5b66\u4e60\u65b9\u6cd5\u3002\u641c\u7d22\u4e4b\u540e\uff0c\u53d1\u73b0\u7f51\u4e0a\u7684\u5f88\u591a\u7ed3\u8bba\u90fd\u4e0d\u592a\u7406\u60f3\uff0c\u4e8e\u662f\u5c31\u9700\u8981\u6211\u81ea\u5df1\u53bb\u601d\u8003\uff0c\u53bb\u63a2\u7d22\u5982\u4f55\u8ba9\u81ea\u5df1\u5199\u7684\u4ee3\u7801\u66f4\u5065\u58ee\uff01\n<\/p>\n<p>\n\t\u6ca1\u6709\u7b54\u6848\u4e4b\u540e\uff0c\u6211\u5c31\u6362\u4e86\u4e00\u79cd\u60f3\u6cd5\u3002Spring \u6846\u67b6\u5927\u5bb6\u90fd\u5728\u4f7f\u7528\u5427\uff0cSpring \u6846\u67b6\u80af\u5b9a\u4e5f\u90fd\u548c\u5065\u58ee\u5427\uff0c\u4e8e\u662f\u6211\u5c31\u662f Spring \u6846\u67b6\u4e2d\u5bfb\u627e\u7b54\u6848\uff01\n<\/p>\n<p>\n\t\u5f53\u7136\uff0c\u7edd\u4e0d\u4ec5\u4ec5\u662f Spring \u6846\u67b6\uff0c\u8fd8\u5305\u62ec\u5176\u4ed6\u4e00\u4e9b\u6846\u67b6\u7684\u6e90\u7801\u3002\u591a\u53bb\u770b\u5b83\u4eec\u7684\u6e90\u7801\uff0c\u53bb\u5bfb\u627e\u7b54\u6848\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u6211\u603b\u7ed3\u4e00\u4e9b\u5173\u4e8e\u4ee3\u7801\u5065\u58ee\u7684\u76f8\u5173\u5efa\u8bae\u3002\n<\/p>\n<p>\n\t\u7b2c\u4e00\u4e2a\uff0c\u6211\u53d1\u73b0 Spring \u6846\u67b6\u6e90\u7801\u4e2d\u5b58\u5728\u5404\u79cd\u5404\u6837\u7684\u65ad\u8a00\u3002Assert.isNull()\u3001Assert.notNull()\u3001Assert.state()\u3001Assert.isTrue()\u3001Assert.notEmpty() \u7b49\u3002\n<\/p>\n<p>\n\t\u4ed6\u4eec\u628a\u975e\u5e38\u591a\u7684 if \u5224\u65ad\u662f\u5426\u4e3a\u7a7a\uff0c\u53c2\u6570\u662f\u5426\u5408\u6cd5\u7b49\u90fd\u7ed9\u5c01\u88c5\u8d77\u6765\u4e86\uff0c\u4ee3\u7801\u663e\u7684\u975e\u5e38\u7b80\u6d01\u3002\n<\/p>\n<p>\n\t\u5c3d\u7ba1 Spring Assert \u4e0e\u5176\u4ed6\u6846\u67b6\u7684\u540d\u79f0\u7c7b\u4f3c\uff0c\u5982 JUnit \u6216\u5176\u4ed6\u6846\u67b6\uff0c\u4f46\u5176\u5b9e\u6ca1\u6709\u4efb\u4f55\u5171\u540c\u4e4b\u5904\u3002Spring Assert \u4e0d\u662f\u4e3a\u4e86\u6d4b\u8bd5\uff0c\u4e5f\u4e0d\u662f\u4e3a\u4e86\u8c03\u8bd5\uff0c\u800c\u662f\u4e3a\u4e86\u65b9\u4fbf\u6821\u9a8c\u4e00\u4e9b\u53c2\u6570\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\nint speed = 0;\r\nAssert.isTrue(speed &gt; 0, &quot;speed must be positive&quot;);\r\nString state = &quot;&quot;;\r\nAssert.state(state.equals(&quot;stop&quot;), &quot;car must be stopped&quot;);\r\nAssert.notNull(state, &quot;state mustn&#039;t be null&quot;);\r\nAssert.isNull(state, &quot;to replace battery the charge must be null&quot;);\r\nAssert.isInstanceOf(String.class, state,&quot;www.xttblog.com&quot;);\r\nAssert.isAssignable(String.class, Object.class,&quot;www.xttblog.com&quot;);\r\nString key = &quot;&quot;;\r\nAssert.hasLength(key, &quot;key must not be null and must not the empty&quot;);\r\nAssert.hasText(\r\n    key,\r\n    &quot;key must not be null and must contain &quot; +\r\n        &quot;at least one non-whitespace character&quot;);\r\nAssert.doesNotContain(key, &quot;123&quot;, &quot;key mustn&#039;t contain 123&quot;);<\/pre>\n<p>\n\t\u9664\u4e86\u4e0a\u9762\u8fd9\u4e9b\uff0cSpring \u6846\u67b6\u4e2d\u7684\u5f88\u591a\u5de5\u5177\u7c7b\uff0c\u4f60\u4f1a\u53d1\u73b0\u91cc\u9762\u6709\u5f88\u591a\u7684\u9759\u6001\u65b9\u6cd5\u3002\u8fd9\u4e2a\u7c7b\u8981\u4e48\u662f final \u7c7b\u578b\u7684\uff0c\u7136\u540e\u6784\u9020\u51fd\u6570\u79c1\u6709\u5316\u3002\u8981\u4e48\u5c31\u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b abstract\u3002\u4f60\u4ee5\u540e\u7684\u5199\u7684\u7c7b\u4e2d\u5168\u662f\u9759\u6001\u65b9\u6cd5\u7684\u8bdd\uff0c\u5c31\u53ef\u4ee5\u8fd9\u6837\u505a\u3002\n<\/p>\n<p>\n\t\u53e6\u5916\u8fd8\u6709\u4e00\u4e9b PO\u3001VO\u3001DO \u7b49\u7c7b\u8981\u5206\u6e05\u695a\u5b83\u4eec\u5404\u81ea\u7684\u7528\u9014\u3002\u4e0d\u7136\u4f1a\u626f\u51fa\u4e0d\u5c11\u7684\u6c34\u5e73\u6743\u9650\u6f0f\u6d1e\u548c\u5782\u76f4\u6743\u9650\u6f0f\u6d1e\u3002\n<\/p>\n<p>\n\t\u4e0d\u80fd\u628a\u81ea\u5df1\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u5efa\u7acb\u5728\u522b\u4eba\u4ee3\u7801\u6b63\u786e\u7684\u57fa\u7840\u4e0a\uff0c\u8fd9\u79cd\u4f9d\u8d56\u5982\u679c\u6210\u4e86\u4e60\u60ef\uff0c\u4f1a\u9ebb\u75f9\u81ea\u5df1\u7684\u8b66\u89c9\u6027\u3002\u8981\u505a\u5230\u5373\u4f7f\u662f\u522b\u4eba\u9519\u4e86\uff0c\u6211\u4eec\u7684\u7a0b\u5e8f\u4f9d\u7136\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u4f7f\u7528\u522b\u4eba\u7684\u53c2\u6570\uff0c\u5fc5\u987b\u8981\u81ea\u5df1\u5728\u6821\u9a8c\u4e00\u904d\u3002\u6700\u5e38\u89c1\u7684\u5c31\u662f\u524d\u7aef\u505a\u4e86\u6821\u9a8c\uff0c\u540e\u7aef\u4e0d\u505a\u6821\u9a8c\u3002\n<\/p>\n<p>\n\t\u5bf9\u4e8e\u8c03\u7528\u7684\u65b9\u6cd5\u4e2d\u5982\u679c\u6709\u5f02\u5e38\u629b\u51fa\uff0c\u5c3d\u91cf\u8981\u81ea\u5df1 try&#8211;catch \u8bed\u53e5\u5757\uff0c\u4ee5\u9632\u53d1\u751f\u975e\u9884\u671f\u7684\u7ed3\u679c\u3002\n<\/p>\n<p>\n\t\u7ed9\u6bcf\u4e2a if(condition){} \u90fd\u52a0\u4e0a\u5927\u62ec\u53f7\uff0c\u5373\u4f7f\u91cc\u9762\u53ea\u6709\u4e00\u53e5\u8bdd\u3002\u963f\u91cc\u5df4\u5df4 Java \u5f00\u53d1\u89c4\u8303\u624b\u518c\u4e2d\u660e\u786e\u5f3a\u8c03\u7684\u3002\n<\/p>\n<p>\n\t\u5e38\u91cf\u7c7b\u4e2d\uff0c\u5c3d\u91cf\u5199\u4e00\u4e9b\u5185\u90e8\u7c7b\uff0c\u628a\u5e38\u91cf\u8fdb\u884c\u533a\u5206\u3002\u5f88\u591a\u5e38\u91cf\u7c7b\u4e2d\u7684\u5e38\u91cf\u9ad8\u8fbe\u4e0a\u767e\u4e2a\uff0c\u6ca1\u6709\u4e00\u70b9\u5f52\u7c7b\u3002\n<\/p>\n<p>\n\t\u5343\u4e07\u522b\u81ea\u5df1\u968f\u610f\u7684\u91cd\u590d\u9020\u8f6e\u5b50\uff0c\u591a\u7528\u4e00\u4e9b\u6846\u67b6\u4e2d\u81ea\u5e26\u7684\u5de5\u5177\u7c7b\u3002\n<\/p>\n<p>\n\t\u6ca1\u6709\u4e0d\u52aa\u529b\u7684\u5929\u624d\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3483\">\u5982\u4f55\u5199\u51fa\u5065\u58ee\u7684 Java \u4ee3\u7801\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5199\u51fa\u5065\u58ee\u7684 Java \u4ee3\u7801\uff1f\u6211\u76f8\u4fe1\u8fd9\u662f\u5f88\u591a\u4eba\u90fd\u6709\u7684\u7591\u60d1\u6216\u8005\u60f3\u8981\u7684\u7b54\u6848\u3002\u4eca\u5929\u6211\u4eec\u62bd\u4e2a\u65f6\u95f4\u4e00\u8d77\u63a2\u8ba8\u4e00\u4e0b\uff01 \u8bf4\u5b9e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[1085,1630,226,1065,578],"class_list":["post-3483","post","type-post","status-publish","format-standard","hentry","category-java","category-yyzt","tag-xfn","tag-1630","tag-226","tag-1065","tag-578"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3483"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3483\/revisions"}],"predecessor-version":[{"id":3484,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3483\/revisions\/3484"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}