Spring Boot Swagger2使用方法過(guò)程解析
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('微信項(xiàng)目接口對(duì)接文檔').description('測(cè)試環(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來(lái)指定刪除對(duì)象') @ApiImplicitParam(name = 'id', value = '用戶ID', required = true, dataType = 'String') @RequestMapping(value='/{id}', method=RequestMethod.DELETE) public String deleteUser(@PathVariable String id) { return 'success'; }}
4.測(cè)試
http://localhost:8080/swagger-ui.html
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP的Global.asa文件技巧用法2. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)3. ASP中if語(yǔ)句、select 、while循環(huán)的使用方法4. ASP中常用的22個(gè)FSO文件操作函數(shù)整理5. SharePoint Server 2019新特性介紹6. 告別AJAX實(shí)現(xiàn)無(wú)刷新提交表單7. Vue+elementUI下拉框自定義顏色選擇器方式8. PHP函數(shù)原理理解詳談9. XML入門的常見(jiàn)問(wèn)題(四)10. 使用css實(shí)現(xiàn)全兼容tooltip提示框
