{"id":927,"date":"2016-11-04T17:10:50","date_gmt":"2016-11-04T09:10:50","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=927"},"modified":"2016-11-04T17:10:50","modified_gmt":"2016-11-04T09:10:50","slug":"swagger2%e6%9e%84%e5%bb%barestful-apis%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=927","title":{"rendered":"Swagger2\u6784\u5efaRESTful APIs\u8be6\u89e3"},"content":{"rendered":"<p>\n\t\u81ea\u4ece restfull \u6982\u5ff5\u88ab\u63d0\u51fa\uff0c\u5404\u79cd\u6846\u67b6 rest \u6846\u67b6\u5982\u96e8\u540e\u6625\u7b0b\u822c\u7684\u5192\u4e86\u51fa\u6765\u3002\u7f51\u4e0a\u4e5f\u6709\u5f88\u591a\u7f51\u53cb\u603b\u7ed3\u4e86spring boot + swagger2 \u7684\u6574\u5408\u7528\u4f8b\u3002\u4f46\u662f\u5f88\u591a\u4f8b\u5b50\u662f\u8fd0\u884c\u4e0d\u6210\u529f\u7684\uff0c\u800c\u4e14\u8fd8\u88ab\u8f6c\u8f7d\u6765\u8f6c\u8f7d\u53bb\u7684\u3002<br \/>\n\t\u672c\u6587\u5c06\u4ece swagger2 \u7684\u6ce8\u89e3\u4e0a\u6765\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528\u5b83\u3002\n<\/p>\n<h2>\n\tswagger\u7528\u4e8e\u5b9a\u4e49API\u6587\u6863<br \/>\n<\/h2>\n<p>\n\t<strong>swagger2\u597d\u5904<\/strong>\n<\/p>\n<ul>\n<li>\n\t\t\u524d\u540e\u7aef\u5206\u79bb\u5f00\u53d1\n\t<\/li>\n<li>\n\t\tAPI\u6587\u6863\u975e\u5e38\u660e\u786e\n\t<\/li>\n<li>\n\t\t\u6d4b\u8bd5\u7684\u65f6\u5019\u4e0d\u9700\u8981\u518d\u4f7f\u7528URL\u8f93\u5165\u6d4f\u89c8\u5668\u7684\u65b9\u5f0f\u6765\u8bbf\u95eeController\n\t<\/li>\n<li>\n\t\t\u4f20\u7edf\u7684\u8f93\u5165URL\u7684\u6d4b\u8bd5\u65b9\u5f0f\u5bf9\u4e8epost\u8bf7\u6c42\u7684\u4f20\u53c2\u6bd4\u8f83\u9ebb\u70e6\uff08\u5f53\u7136\uff0c\u53ef\u4ee5\u4f7f\u7528postman\u8fd9\u6837\u7684\u6d4f\u89c8\u5668\u63d2\u4ef6\uff09\n\t<\/li>\n<li>\n\t\tspring-boot\u4e0eswagger\u7684\u96c6\u6210\u7b80\u5355\u7684\u4e00\u903c\n\t<\/li>\n<\/ul>\n<h2>\n\tswagger2 \u6ce8\u89e3\u8bf4\u660e<br \/>\n<\/h2>\n<ul>\n<li>\n\t\t@Api\uff1a\u7528\u5728\u7c7b\u4e0a\uff0c\u8bf4\u660e\u8be5\u7c7b\u7684\u4f5c\u7528\n\t<\/li>\n<li>\n\t\t@ApiOperation\uff1a\u7528\u5728\u65b9\u6cd5\u4e0a\uff0c\u8bf4\u660e\u65b9\u6cd5\u7684\u4f5c\u7528\n\t<\/li>\n<li>\n\t\t@ApiImplicitParams\uff1a\u7528\u5728\u65b9\u6cd5\u4e0a\u5305\u542b\u4e00\u7ec4\u53c2\u6570\u8bf4\u660e\n\t<\/li>\n<li>\n\t\t@ApiImplicitParam\uff1a\u7528\u5728@ApiImplicitParams\u6ce8\u89e3\u4e2d\uff0c\u6307\u5b9a\u4e00\u4e2a\u8bf7\u6c42\u53c2\u6570\u7684\u5404\u4e2a\u65b9\u9762<\/p>\n<ul>\n<li>\n\t\t\t\tparamType\uff1a\u53c2\u6570\u653e\u5728\u54ea\u4e2a\u5730\u65b9<\/p>\n<ul>\n<li>\n\t\t\t\t\t\theader&#8211;&gt;\u8bf7\u6c42\u53c2\u6570\u7684\u83b7\u53d6\uff1a@RequestHeader\n\t\t\t\t\t<\/li>\n<li>\n\t\t\t\t\t\tquery&#8211;&gt;\u8bf7\u6c42\u53c2\u6570\u7684\u83b7\u53d6\uff1a@RequestParam\n\t\t\t\t\t<\/li>\n<li>\n\t\t\t\t\t\tpath\uff08\u7528\u4e8erestful\u63a5\u53e3\uff09&#8211;&gt;\u8bf7\u6c42\u53c2\u6570\u7684\u83b7\u53d6\uff1a@PathVariable\n\t\t\t\t\t<\/li>\n<li>\n\t\t\t\t\t\tbody\uff08\u4e0d\u5e38\u7528\uff09\n\t\t\t\t\t<\/li>\n<li>\n\t\t\t\t\t\tform\uff08\u4e0d\u5e38\u7528\uff09\n\t\t\t\t\t<\/li>\n<\/ul>\n<\/li>\n<li>\n\t\t\t\tname\uff1a\u53c2\u6570\u540d\n\t\t\t<\/li>\n<li>\n\t\t\t\tdataType\uff1a\u53c2\u6570\u7c7b\u578b\n\t\t\t<\/li>\n<li>\n\t\t\t\trequired\uff1a\u53c2\u6570\u662f\u5426\u5fc5\u987b\u4f20\n\t\t\t<\/li>\n<li>\n\t\t\t\tvalue\uff1a\u53c2\u6570\u7684\u610f\u601d\n\t\t\t<\/li>\n<li>\n\t\t\t\tdefaultValue\uff1a\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\n\t\t\t<\/li>\n<\/ul>\n<\/li>\n<li>\n\t\t@ApiResponses\uff1a\u7528\u4e8e\u8868\u793a\u4e00\u7ec4\u54cd\u5e94\n\t<\/li>\n<li>\n\t\t@ApiResponse\uff1a\u7528\u5728@ApiResponses\u4e2d\uff0c\u4e00\u822c\u7528\u4e8e\u8868\u8fbe\u4e00\u4e2a\u9519\u8bef\u7684\u54cd\u5e94\u4fe1\u606f<\/p>\n<ul>\n<li>\n\t\t\t\tcode\uff1a\u6570\u5b57\uff0c\u4f8b\u5982400\n\t\t\t<\/li>\n<li>\n\t\t\t\tmessage\uff1a\u4fe1\u606f\uff0c\u4f8b\u5982&quot;\u8bf7\u6c42\u53c2\u6570\u6ca1\u586b\u597d&quot;\n\t\t\t<\/li>\n<li>\n\t\t\t\tresponse\uff1a\u629b\u51fa\u5f02\u5e38\u7684\u7c7b\n\t\t\t<\/li>\n<\/ul>\n<\/li>\n<li>\n\t\t@ApiModel\uff1a\u63cf\u8ff0\u4e00\u4e2aModel\u7684\u4fe1\u606f\uff08\u8fd9\u79cd\u4e00\u822c\u7528\u5728post\u521b\u5efa\u7684\u65f6\u5019\uff0c\u4f7f\u7528@RequestBody\u8fd9\u6837\u7684\u573a\u666f\uff0c\u8bf7\u6c42\u53c2\u6570\u65e0\u6cd5\u4f7f\u7528@ApiImplicitParam\u6ce8\u89e3\u8fdb\u884c\u63cf\u8ff0\u7684\u65f6\u5019\uff09<\/p>\n<ul>\n<li>\n\t\t\t\t@ApiModelProperty\uff1a\u63cf\u8ff0\u4e00\u4e2amodel\u7684\u5c5e\u6027\n\t\t\t<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\n\t\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"swagger2 \u6574\u5408 spring boot\" src=\"http:\/\/images2015.cnblogs.com\/blog\/866881\/201604\/866881-20160405160238047-1725111637.png\" style=\"width: 705px;height: 168px\" \/>\n<\/p>\n<p>\n\t\u5982\u679cApiImplicitParam\u4e2d\u7684phone\u7684paramType\u662fquery\u7684\u8bdd\uff0c\u662f\u65e0\u6cd5\u6ce8\u5165\u5230rest\u8def\u5f84\u4e2d\u7684\uff0c\u800c\u4e14\u5982\u679c\u662fpath\u7684\u8bdd\uff0c\u662f\u4e0d\u9700\u8981\u914d\u7f6eApiImplicitParam\u7684\uff0c\u5373\u4f7f\u914d\u7f6e\u4e86\uff0c\u5176\u4e2d\u7684value=&quot;\u624b\u673a\u53f7&quot;\u4e5f\u4e0d\u4f1a\u5728swagger-ui\u5c55\u793a\u51fa\u6765\u3002\n<\/p>\n<p>\n\t\u542f\u52a8\u670d\u52a1\uff0c\u6d4f\u89c8\u5668\u8f93\u5165&quot;http:\/\/localhost:8080\/swagger-ui.html&quot;\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"swagger2 \u6d4b\u8bd5\" src=\"http:\/\/images2015.cnblogs.com\/blog\/866881\/201604\/866881-20160402194015223-1123677403.png\" style=\"width: 866px;height: 821px\" \/><\/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=927\">Swagger2\u6784\u5efaRESTful APIs\u8be6\u89e3<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u81ea\u4ece restfull \u6982\u5ff5\u88ab\u63d0\u51fa\uff0c\u5404\u79cd\u6846\u67b6 rest \u6846\u67b6\u5982\u96e8\u540e\u6625\u7b0b\u822c\u7684\u5192\u4e86\u51fa\u6765\u3002\u7f51\u4e0a\u4e5f\u6709\u5f88\u591a\u7f51\u53cb\u603b\u7ed3\u4e86sp [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[606,605,607,604,603],"class_list":["post-927","post","type-post","status-publish","format-standard","hentry","category-java","tag-apiimplicitparam","tag-apioperation","tag-enableswagger2","tag-restfull","tag-swagger2"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/927","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=927"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/927\/revisions"}],"predecessor-version":[{"id":928,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/927\/revisions\/928"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}