美文网首页
Swagger基本使用

Swagger基本使用

作者: 因你而在_caiyq | 来源:发表于2021-03-03 10:32 被阅读0次

    原创文章,转载请注明原文章地址,谢谢!

    <dependency>
       <groupId>io.springfox</groupId>
       <artifactId>springfox-swagger2</artifactId>
       <version>2.6.1</version>
    </dependency>
    <dependency>
       <groupId>io.springfox</groupId>
       <artifactId>springfox-swagger-ui</artifactId>
       <version>2.6.1</version>
    </dependency>
    
    @Configuration
    @EnableSwagger2
    public class Swagger2 {
    
        @Bean
        public Docket createRestApi() {
            Docket docket = null;
            docket = new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                    .paths(PathSelectors.any())
                    .build();
            return docket;
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("百度-微服务")
                    .description("百度一下,你就知道")
                    .termsOfServiceUrl("www.baidu.com")
                    .contact("微服务小组")
                    .version("1.0")
                    .build();
        }
    }
    
    @Api(value = "Demo", description = "Demo接口")
    @RestController
    @RequestMapping("/demo")
    public class SwaggerDemoController {
    
        @ApiOperation(value = "小样", notes = "小样", response = Object.class)
        @ApiImplicitParams({
                @ApiImplicitParam(name = "id", value = "id", dataType = "string", paramType = "query"),
                @ApiImplicitParam(name = "content", value = "内容", dataType = "string", paramType = "query")
        })
        @RequestMapping(value = "/hello", method = {RequestMethod.GET, RequestMethod.POST})
        public String hello(@RequestParam("id") String id, @RequestParam(name = "content", required = false) String content) {
            return id + content;
        }
    }
    

    博客内容仅供自已学习以及学习过程的记录,如有侵权,请联系我删除,谢谢!

    相关文章

      网友评论

          本文标题:Swagger基本使用

          本文链接:https://www.haomeiwen.com/subject/jbeztltx.html