日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Swagger2+Apizza接口文档

發布時間:2023/12/20 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Swagger2+Apizza接口文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Swagger2的使用

// 這個是基于Springboot環境 <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version> </dependency> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version> </dependency>

Swagger2接口文檔說明

定義swagger配置類 放到啟動類能掃到的地方

package com.itheima.health.config;import com.itheima.health.ConsumerMain; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration @EnableSwagger2 public class SwaggerConfig {@Beanpublic Docket createRestApi() {String basePck = WebApplicaiton.class.getPackage().getName();System.out.println(basePck+"=啟動類所在的包為路徑掃描=====定義生成接口文檔的包路徑=====");return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(basePck)).paths(PathSelectors.any()).build();}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("傳智播客_傳智健康_接口文檔").description("描述內容").version("2.1.1").build();}}

啟動類

package com.itheima;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import springfox.documentation.swagger2.annotations.EnableSwagger2;@SpringBootApplication @EnableSwagger2 // 開啟swagger配置 public class WebApplication {public static void main(String[] args) {SpringApplication.run(WebApplication.class,args);System.out.println("===health_web消費端啟動---");} }

Swagger常用注解說明


常用兩個注解: 一個類 和 一個方法

@Api 和 @ApiOperation
示例: controller包下開發檢查項所有列表查詢

//第一種無參數的情況下

// 這個是無參的 @RestController @Api(tags = "檢查項模塊管理") public class CheckItemController {@Referenceprivate CheckItemService checkItemService;// 開發 檢查項模塊 crud@GetMapping("checkitem/findAll")@ApiOperation(value = "查詢檢查項方法",notes = "查詢所有的檢查項列表信息")public Result findAll(){List<CheckItem> list = checkItemService.list();return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);} }

//第二種有參數的情況下

@ApiOperation(value = "套餐查詢",notes = "分頁套餐查詢")@ApiImplicitParams({@ApiImplicitParam(name="currentPage",value="當前分頁頁碼",required=true,paramType="form",dataType="Integer"),@ApiImplicitParam(name="pageSize",value="每頁顯示記錄數",required=true,paramType="form",dataType="Integer"),@ApiImplicitParam(name="queryString",value="查詢條件",required=false,paramType="form",dataType="String")})@ApiResponses({@ApiResponse(code=400,message="請求參數沒填好"),@ApiResponse(code=404,message="請求路徑沒有或頁面跳轉路徑不對")})// 上述注解 添加在目標方法上! public Result findPage(@RequestBody QueryPageBean queryPageBean){PageResult pageResult = setmealService.findPage(queryPageBean);return new Result(pageResult);}

訪問頁面: 查詢文檔接口
去這個網頁上能下載
http://localhost:8081/swagger-ui.html

總結

以上是生活随笔為你收集整理的Swagger2+Apizza接口文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。