idea中 swagger-ui的配置

 一:在maven中配置相应的配置文件


   io.springfox
   springfox-swagger2
   2.7.0


   io.springfox
   springfox-swagger-ui
   2.7.0

 二:配置swagger对应的controller包名和api文档名

package com.hopson.manager;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author lizhiyuan
 * @ClassName cn.saytime.Swgger2
 * @Description
 * @date 2017-07-10 22:12:31
 */
@Configuration
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hopson.manager.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("合生活品质生活api文档")
                .description("合生活品质生活api文档")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }
}

效果如图

 三:在application类中添加@EnableSwagger2的注解

@ServletComponentScan
@EnableTransactionManagement
@EnableSwagger2
@EnableCaching
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
public class HopsonLifeAdvertApplication {
   public static final Logger logger = LoggerFactory.getLogger(HopsonLifeAdvertApplication.class);
   public static void main(String[] args) {
      SpringApplication.run(HopsonLifeAdvertApplication.class, args);
   }
   @Bean
   public PlatformTransactionManager txManager(DataSource dataSource) {
      return new DataSourceTransactionManager(dataSource);
   }
}

 

四:在controller类中添加相应的注解

@Api

用于类;表示标识这个类是swagger的资源 
tags–表示说明 
value–也是说明,可以使用tags替代 
但是tags如果有多个值,会生成多个list

@Api(value = "类别信息",tags={"类别接口-小张先生2333"})

@ApiOperation和@ApiImplicitParam

@ApiOperation  用于方法,表示一个http请求的操作 
  参数:

          value用于方法描述 
          notes用于提示内容 
          tags可以重新分组(视情况而用) 

        @ApiOperation(value="获取检查类别信息列表", notes="{\"checkClass\":\"安全\"," +
        "\"pageSize\":10,\"pageNo\":1,\"begin\":0}")

@ApiImplicitParam 用于方法 表示单独的请求参数 

    name–参数ming 
    value–参数说明 
    dataType–数据类型 
    paramType–参数类型 
    example–举例说明

@ApiImplicitParam(name = "param", value = "查询条件", required = true, dataType = "String", paramType = "query")

 

你可能感兴趣的:(idea中 swagger-ui的配置)