Spring Boot Swagger2使用方法過程解析
1.添加Swagger2依賴
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version></dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version></dependency>
2配置類
@Configuration@EnableSwagger2public class Swagger2 { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage('com.bs.swaggertest.controller')).paths(PathSelectors.any()).build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder().title('微信項目接口對接文檔').description('測試環(huán)境接口調(diào)試').contact('陶海軍').version('1.0').build(); }}
3.添加文檔內(nèi)容
@RestController@RequestMapping(value='/users')public class UserController { @ApiOperation(value='刪除用戶', notes='根據(jù)url的id來指定刪除對象') @ApiImplicitParam(name = 'id', value = '用戶ID', required = true, dataType = 'String') @RequestMapping(value='/{id}', method=RequestMethod.DELETE) public String deleteUser(@PathVariable String id) { return 'success'; }}
4.測試
http://localhost:8080/swagger-ui.html
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Spring security 自定義過濾器實現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實例代碼)2. docker /var/lib/docker/aufs/mnt 目錄清理方法3. JAMon(Java Application Monitor)備忘記4. Python OpenCV去除字母后面的雜線操作5. 在Mac中配置Python虛擬環(huán)境過程解析6. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法7. IntelliJ IDEA設(shè)置背景圖片的方法步驟8. Python TestSuite生成測試報告過程解析9. Python 的 __str__ 和 __repr__ 方法對比10. Java類加載機(jī)制實現(xiàn)步驟解析
