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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringFox swagger2 and SpringFox swagger2 UI 接口文档生成与查看

發布時間:2023/12/1 javascript 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringFox swagger2 and SpringFox swagger2 UI 接口文档生成与查看 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

依賴:

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version> </dependency>

?

使用:在你要生成接口處加上注解@EnableSwagger2? ,此處是整個項目都要,不建議這么玩, 建議加在controller上

?

@SpringBootApplication @EnableSwagger2 public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);} }

?

?自定義標題:配置:(這個可以不配置)

@Configuration @EnableSwagger2 public class Swagger2Config {@Beanpublic Docket createRestApi() {// ParameterBuilder ticketPar = new ParameterBuilder();// List<Parameter> pars = new ArrayList<Parameter>();// ticketPar.name("Authorization").description("登錄校驗")//name表示名稱,description表示描述// .modelRef(new ModelRef("string")).parameterType("header")// .required(false).defaultValue("Bearer// ").build();//required表示是否必填,defaultvalue表示默認值// pars.add(ticketPar.build());//添加完此處一定要把下邊的帶***的也加上否則不生效
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(com.test.move.user.controller)) //指定暴露的AIP接口.paths(PathSelectors.any()).build();// .globalOperationParameters(pars);}private ApiInfo apiInfo() {return new ApiInfoBuilder().title("XXX api 文檔").description("這是XXX API 文檔的說明") //自定義標題和說明.termsOfServiceUrl("http://www.XXX.com/") //指定訪問的URL.contact(new Contact("xiaowang", "", "xiaowang@163.com")).build();} }

  

?

?

?

方法描述: 在方法上加上 @ApiOperation

@ApiOperation(value="這是一個上傳excel的方法")@PostMapping("/uploadExcel")public CommonResponse uploadOrderExcel(@RequestParam("ePlusExcel") MultipartFile ePlusExcel,)

?效果:

?

?參數描述:1. 參數是? 包裝類 或者模型 如PartDO   在屬性上加 @ApiModelProperty(value="")

@ApiModelProperty(value="part 的 描述")private String partDesc;

?參數描述:2. 參數是? 普通類型 如String? name   在屬性上加@ApiParam(value="")

@GetMapping("/queryInventory")public CommonResponse queryInventory(@ApiParam(value="客戶編碼")String customerCode) {

效果:

?

?

?

?

?

?

?查看: http://localhost:9999/swagger-ui.html

?

轉載于:https://www.cnblogs.com/lshan/p/9571265.html

總結

以上是生活随笔為你收集整理的SpringFox swagger2 and SpringFox swagger2 UI 接口文档生成与查看的全部內容,希望文章能夠幫你解決所遇到的問題。

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