SpringFox swagger2 and SpringFox swagger2 UI 接口文檔生成與查看
阿新 • • 發佈:2018-09-01
spring str 接口 des string query oot tps Inventor
依賴:
<!-- 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 publicclass Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
方法描述: 在方法上加上 @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
SpringFox swagger2 and SpringFox swagger2 UI 接口文檔生成與查看