zoukankan      html  css  js  c++  java
  • Swagger2文档生成器

    Swagger2配置文件:

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
        private ApiInfo apiInfo(){
            return new ApiInfoBuilder().title("增删改的restful风格")
                    .description("中公教育优就业")
                    .termsOfServiceUrl("http://ujiuye")
                    .contact("sunny")
                    .version("1.0")
                    .build();
        }
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.offcn.demo01.web"))
                    .paths(PathSelectors.any())
                    .build();
        }
    }

    web层的接口方法加注解:

     @ApiOperation(value="更新指定name用户", notes = "根据name修改用户信息")
        @ApiImplicitParams({
                @ApiImplicitParam(name="name",value = "用户姓名",required = true,dataType = "String"),
                @ApiImplicitParam(name="userBody",value="用户的详细信息",required = true,dataType = "UserBody")
        })
        @PutMapping("/{name}")
        public void put(UserBody userBody,@PathVariable("name") String name){
            for (UserBody body : list) {
                if(body.getName() .equals(name)){
                    body.setDate(userBody.getDate());
                }
            }
        }

    swagger2所需的依赖

     <!-- 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>

  • 相关阅读:
    MVC中使用AuthorizeAttribute做身份验证操作
    MVC Dynamic Authorization--示例市在Action前进行的验证,应提前到Auth过滤器
    forms
    UEditor
    Test log4net
    log4net.config
    [转]log4net使用(WinForm/WebFrom)
    如何指定模型的显示格式和模板
    64位系统中连接Access数据库文件的一个问题
    VS2008简体中文正式版序列号
  • 原文地址:https://www.cnblogs.com/wycBolg/p/11802228.html
Copyright © 2011-2022 走看看