• SpringBoot整合Swagger2


    1.pom.xml导入依赖:

    <!-- swagger -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.5.0</version>
    </dependency>
    <!-- swagger-ui -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.5.0</version>
    </dependency>

    2.添加配置类SwaggerConfig:

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.system.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
        private ApiInfo apiInfo(){
            return new ApiInfoBuilder()
                    .title("springboot利用swagger构建api文档")
                    .description("简单优雅的swagger风格")
                    .termsOfServiceUrl("http://")
                    .version("1.0")
                    .build();
        }
    }

    3. Controller层

    @RestController
    @Api(description = "登录接口")
    public class LoginController {
        @ApiOperation(value = "用户登录" ,  notes="登录")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "username",dataType = "String",paramType = "query"),
                @ApiImplicitParam(name = "password",dataType = "String",paramType = "query"),
        })
        @PostMapping(value = "/login")
        public void login(String username,String password){
            System.err.println(username+"  "+password);
        }
    }

    4.访问 http://localhost:8080/swagger-ui.html

  • 相关阅读:
    jQuery插件实现简单的圆角
    提高网页效率的14条准则
    jQuery插件sdmenu导航插件
    Using MVC Pattern in Web Interactions
    jQuery插件源代码显示.(Ajax加载方式).
    jQuery插件jLook(表单美化)
    jQuery关于 序列化
    jQueryblockUIV2翻译.
    cssimagemap
    jQuerySlide menu
  • 原文地址:https://www.cnblogs.com/angel-devil/p/11935412.html
Copyright © 2020-2023  润新知