
Swagger接口文档
目录第一步添加依赖第二步添加配置①新建一个config包,写配置类②加入api注解,在controller类上面编辑③每个方法上加入@ApiOperation注解,生成对应api第三步在线测试接口重启项目打开网页进入访问地址出现此页面表示成功展开查看详情输入要查询的名字测试结果Swagger 是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。第一步添加依
·
目录
③每个方法上加入@ApiOperation注解,生成对应api
Swagger 是一个规范且完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。
第一步添加依赖
<!--添加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>
第二步添加配置
①新建一个config包,写配置类
package com.qiu.config;
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.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
//表示这个类是一个配置类,会把这个类注入到ioc容器中
@Configuration
//开启swagger2的功能
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//这里一定要标注你控制器的位置
.apis(RequestHandlerSelectors.basePackage("com.qiu.controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Thymeleaf测试")
.description("SpringBoot整合Thymeleaf测试")
.termsOfServiceUrl("https://angegit.gitee.io/myblog/")
.contact(new Contact("niechangan","https://angegit.gitee.io/myblog/","1351261434@qq.com"))
.version("1.0")
.build();
}
}
②加入api注解,在controller类上面
③每个方法上加入@ApiOperation注解,生成对应api
//value 简单描述,notes 详细描述
@ApiOperation(value = "删除用户",notes = "根据id删除用户")
@DeleteMapping("/deleteById")
public boolean deleteById( Integer id){
boolean b = userService.removeById(id);
return b;
}
第三步在线测试接口
重启项目打开网页进入访问地址
访问地址:http://localhost:8080/swagger-ui.html
注:端口号要写自己的
出现此页面表示成功
展开查看详情
输入要查询的名字测试
结果
更多推荐
所有评论(0)
您需要登录才能发言
加载更多