Swagger

整合Springboot

依赖

https://mvnrepository.com/artifact/io.springfox/springfox-swagger2/2.9.2

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

配置

  • 默认地址http://localhost:8080/swagger-ui.html
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    static final String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Restful APIs")
                .description("restful api doc")
                .version(VERSION).build();
    }

}

应用

    @ApiOperation(value = "测试接口", notes = "接口说明")
    @ApiImplicitParams(
        @ApiImplicitParam(name = "index", value = "测试参数", paramType = "query", dataType = "String")
    )
    @RequestMapping("/list")
    public Object list(String index) {
        return deviceService.list();
    }

整合SSM

posted @ 2020-11-19 21:00  熊云港  阅读(96)  评论(0编辑  收藏  举报