{"id":702,"date":"2023-11-12T09:01:01","date_gmt":"2023-11-12T01:01:01","guid":{"rendered":""},"modified":"2023-11-12T09:01:01","modified_gmt":"2023-11-12T01:01:01","slug":"\u6574\u5408\u63a5\u53e3\u6587\u6863\u5de5\u5177swagger","status":"publish","type":"post","link":"https:\/\/mushiming.com\/702.html","title":{"rendered":"\u6574\u5408\u63a5\u53e3\u6587\u6863\u5de5\u5177swagger"},"content":{"rendered":"

Swagger\u63a5\u53e3\u7ba1\u7406\u5de5\u5177\u53ef\u65b9\u4fbf\u5f00\u53d1\u6d4b\u8bd5\u548c\u524d\u540e\u8054\u8c03\uff0c\u96c6\u6210\u8d77\u6765\u4e5f\u5f88\u65b9\u4fbf\u3002<\/h1>\n

\u5f15\u5165\u4f9d\u8d56<\/h1>\n
<!--swagger\uff0c \u82e5\u6ca1\u6709parent\u9879\u76ee\uff0c\u989d\u5916\u6dfb\u52a0\u7248\u672c\u6807\u7b7e--><\/span>\n<dependency<\/span>><\/span>\n  <groupId<\/span>><\/span>io.springfox<\/groupId<\/span>><\/span>\n  <artifactId<\/span>><\/span>springfox-swagger2<\/artifactId<\/span>><\/span>\n<\/dependency<\/span>><\/span>\n<!--swagger ui--><\/span>\n<dependency<\/span>><\/span>\n  <groupId<\/span>><\/span>io.springfox<\/groupId<\/span>><\/span>\n  <artifactId<\/span>><\/span>springfox-swagger-ui<\/artifactId<\/span>><\/span>\n<\/dependency<\/span>><\/span>\n<\/code><\/pre>\n

\u914d\u7f6e\u7c7b<\/h1>\n
@Configuration<\/span>\n@EnableSwagger2<\/span>\npublic<\/span> class<\/span> Swagger2Config<\/span> {\n\n    @Bean<\/span>\n    public<\/span> Docket AdminapiConfig<\/span>()<\/span>{\n        return<\/span> new<\/span> Docket<\/span>(DocumentationType.SWAGGER_2).groupName(\"\u7ba1\u7406\u5458Api\"<\/span>)\n\/\/ \u63a5\u53e3\u6587\u6863\u5206\u7ec4\uff0c\u8fc7\u6ee4\u63a5\u53e3\uff0c\u9009\u62e9-\u8def\u5f84-\u6b63\u5219\u8868\u8fbe\u5f0f<\/span>\n                .apiInfo(adminApiInfo()) \/\/\u81ea\u5b9a\u4e49\u65b9\u6cd5\uff0c\u63cf\u8ff0\u5c55\u793a\u4fe1\u606f<\/span>\n                .select()\n                .paths(Predicates.and(PathSelectors.regex(\"\/admin\/.*\"<\/span>)))\n                .build();\n    }\n\/\/ \u6587\u6863\u4fe1\u606f\u5c55\u793a<\/span>\n    private<\/span> ApiInfo adminApiInfo<\/span>()<\/span>{\n        return<\/span> new<\/span> ApiInfoBuilder<\/span>()\n                .title(\"p2p\u501f\u6b3e\u5e73\u53f0\u7ba1\u7406\u5458api\u6587\u6863\"<\/span>)\n                .description(\"\u5e73\u53f0\u7ba1\u7406\u5458\u7684api\u63a5\u53e3\u5c55\u793a\"<\/span>)\n                .version(\"1.0\"<\/span>)\n                .contact(new<\/span> Contact<\/span>(\"Skiray\"<\/span>,\"https:\/\/blog.csdn.net\/CC1770374\/\"<\/span>,\"Skiray.foxmail.com\"<\/span>))\n                .build();\n    }\n\n    @Bean<\/span>\n    public<\/span> Docket WebapiConfig<\/span>()<\/span>{\n        return<\/span> new<\/span> Docket<\/span>(DocumentationType.SWAGGER_2).groupName(\"\u666e\u901aApi\"<\/span>)\n                .apiInfo(webApiInfo())\n                .select()\n                .paths(Predicates.and(PathSelectors.regex(\"\/api\/.*\"<\/span>)))\n                .build();\n    }\n    private<\/span> ApiInfo webApiInfo<\/span>()<\/span>{\n        return<\/span> new<\/span> ApiInfoBuilder<\/span>()\n                .title(\"p2p\u501f\u6b3e\u5e73\u53f0\u666e\u901a\u7528\u6237api\u6587\u6863\"<\/span>)\n                .description(\"\u5e73\u53f0\u666e\u901a\u7528\u6237\u7684api\u63a5\u53e3\u5c55\u793a\"<\/span>)\n                .version(\"1.0\"<\/span>)\n                .contact(new<\/span> Contact<\/span>(\"Skiray\"<\/span>,\"https:\/\/blog.csdn.net\/CC1770374\/\"<\/span>,\"Skiray.foxmail.com\"<\/span>))\n                .build();\n    }\n}\n<\/code><\/pre>\n

\u63a5\u53e3<\/h1>\n
@Api(tags = \"\u79ef\u5206\u7ba1\u7406\")<\/span>\n@CrossOrigin<\/span> \/\/\u5141\u8bb8\u8de8\u57df\u8bf7\u6c42,\u6d4b\u8bd5\u7528<\/span>\n@RestController<\/span>\n@RequestMapping(\"admin\/core\/integralGrade\")<\/span>\npublic<\/span> class<\/span> AdminIntegralGradeController<\/span> {\n\n    @Resource<\/span>\n    private<\/span> IntegralGradeService integralGradeService;\n\n    @ApiOperation(\"\u83b7\u53d6\u79ef\u5206\u5217\u8868\")<\/span>\n    @GetMapping(\"\/list\")<\/span>\n    public<\/span> List<IntegralGrade> listAll<\/span>()<\/span>{\n        return<\/span> integralGradeService.list();\n    }\n\n    @ApiOperation(value = \"\u6839\u636eid\u5220\u9664\u79ef\u5206\u6570\u636e\", notes = \"\u903b\u8f91\u5220\u9664\u79ef\u5206\u8bb0\u5f55\")<\/span>\n    @DeleteMapping(\"remove\/{id}\")<\/span>\n    public<\/span> boolean<\/span> deleteById<\/span>( @PathVariable<\/span> @ApiParam(value = \"\u6570\u636eid\",example = \"100\",required = true)<\/span> Long id )<\/span>{\n        return<\/span> integralGradeService.removeById(id);\n    }\n\n}\n<\/code><\/pre>\n

\u6ce8\u89e3<\/h1>\n

\u5b9e\u4f53\u7c7b<\/h2>\n
@ApiModel(value = \"\" ,description = \"\")<\/span> \/\/ \u5b9e\u4f53\u7c7b\u540d\u79f0<\/span>\n\n\n@ApiModelProperty(value = \"\",example = \" \")<\/span> \/\/\u5b9e\u4f53\u7c7b\u6027\u540d<\/span>\n<\/code><\/pre>\n

Controller<\/h2>\n
@Api(tags = \"\")<\/span> \/\/\u63a5\u53e3\u7684\u540d\u79f0\u63cf\u8ff0 \uff0c\u4ee5\u5355\u4e2aController\u6587\u4ef6\u4e3a\u4e00\u7ec4<\/span>\n\n@ApiOperation(value = \"\u6839\u636eid\u5220\u9664\u79ef\u5206\u6570\u636e\", notes = \"\u903b\u8f91\u5220\u9664\u79ef\u5206\u8bb0\u5f55\")<\/span>\/\/\u5355\u4e2a\u63a5\u53e3\u7684\u63cf\u8ff0<\/span>\n\n@ApiParam(value = \"\u6570\u636eid\",example = \"100\",required = true)<\/span> \/\/\u63a5\u53e3\u53c2\u6570\u63cf\u8ff0<\/span>\n<\/code><\/pre>\n

\u5c55\u793a<\/h1>\n

\"\u6574\u5408\u63a5\u53e3\u6587\u6863\u5de5\u5177swagger<\/p>\n","protected":false},"excerpt":{"rendered":"\u6574\u5408\u63a5\u53e3\u6587\u6863\u5de5\u5177swaggerSwagger\u63a5\u53e3\u7ba1\u7406\u5de5\u5177\u53ef\u65b9\u4fbf\u5f00\u53d1\u6d4b\u8bd5\u548c\u524d\u540e\u8054\u8c03\uff0c\u96c6\u6210\u8d77\u6765\u4e5f\u5f88\u65b9\u4fbf\u3002 \u5f15\u5165\u4f9d\u8d56 \u914d\u7f6e\u7c7b \u63a5\u53e3 \u6ce8\u89e3 \u5b9e\u4f53...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/702"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=702"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/702\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}