springboot-swagger配置
Posted liu1275271818
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springboot-swagger配置相关的知识,希望对你有一定的参考价值。
原文地址
https://www.cnblogs.com/softidea/p/6251249.html
https://www.cnblogs.com/xiebq/p/9181517.html
1pomjar包
<!--swagger 文档注释--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.7.0</version> </dependency> <!--swagger-->
2配置类
package com.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.schema.ModelRef; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Parameter; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import java.util.ArrayList; import java.util.List; @Configuration @EnableSwagger2 public class Swagger2Config { @Bean public Docket createRestApi() { List<Parameter> pars = new ArrayList<Parameter>(); return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) .paths(PathSelectors.any()) .build() .globalOperationParameters(pars) .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("功能 RESTful API") //.description("展示先做基础功能,后面再添加业务") //.termsOfServiceUrl("https://www.cnblogs.com/xiebq/") .version("1.0") .build(); } }
3项目启动
http://localhost:端口号/swagger-ui.html 启动项目数据网址就能点开
@ApiOperation方法注解
-value 功能描述,
-produces 返回值类型
=========================
@Api类注解
-tags 功能描述
以上是关于springboot-swagger配置的主要内容,如果未能解决你的问题,请参考以下文章