使用Swagger生成简单接口文档
使用swagger通过简单的配置可以生成简单的接口文档;
依赖包:
// Swagger2
compile 'io.springfox:springfox-swagger2:2.8.0'
compile 'io.springfox:springfox-swagger-ui:2.8.0'
启动类添加配置:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
@EnableAutoConfiguration
public class ShowCaseApplication { public static void main(String[] args) {
SpringApplication.run(ShowCaseApplication.class, args);
}
}
配置类:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration
@ComponentScan(basePackages = { //"com.a.controller", //
})
@EnableSwagger2
public class AutoConfiguration { @Bean
public Docket docketCommon() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test").select()
.apis(RequestHandlerSelectors.basePackage("com.a.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(new ApiInfoBuilder().
title("test Restful API").
description("接口API").
contact(new Contact("", "", "")).
version("1.0").
build());
}
}
接口注释:在controller里的接口上面添加标识
@ApiOperation(nickname = "getList", value = "获取列表。")
@Override
public List<String> getList(
@RequestBody @ApiParam(name = "请求对象", value = "传入json格式", required = true) TestRequest request) {
return null
}
使用Swagger生成简单接口文档的更多相关文章
- spring boot使用swagger生成api接口文档
前言 在之前的文章中,使用mybatis-plus生成了对应的包,在此基础上,我们针对项目的api接口,添加swagger配置和注解,生成swagger接口文档 具体可以查看本站spring boot ...
- .NET Core WEB API使用Swagger生成在线接口文档
1项目引用Swashbuckle.AspNetCore程序集和Microsoft.Extensions.PlatformAbstractions程序集 右击项目打开"管理NuGet程序包.. ...
- swagger 生成的接口文档,隐藏接口的某个参数
[问题描述] controller 中的处理请求的方法,有时候会添加一些额外的参数.比如下面代码中 UserVo: @PostMapping(value = "/add-office-par ...
- .netcore Swagger 生成 api接口文档
1, 引用第三方包, Swashbuckle.AspNetCore Swashbuckle.AspNetCore.Swagger Swashbuckle.AspNetCore.SwaggerUI 最简 ...
- Swagger+Spring mvc生成Restful接口文档
简介 Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法,参数和模型紧密集 ...
- Spring Boot 集成 Swagger 生成 RESTful API 文档
原文链接: Spring Boot 集成 Swagger 生成 RESTful API 文档 简介 Swagger 官网是这么描述它的:The Best APIs are Built with Swa ...
- Spring MVC学习总结(9)——Spring MVC整合swagger自动生成api接口文档
Swagger 号称:世界最流行的API框架,官网:http://swagger.io/,Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总 ...
- Swagger: 一个restful接口文档在线生成+功能测试软件
一.什么是 Swagger? Swagger 是一款RESTFUL接口的文档在线自动生成+功能测试功能软件.Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 ...
- springboot项目利用Swagger2生成在线接口文档
Swagger简介. Swagger2是一款restful接口文档在线生成和在线调试工具.很多项目团队利用Swagger自动生成接口文档,保证接口文档和代码同步更新.在线调试.简单地说,你可以利用这个 ...
随机推荐
- solrcloud上传collection配置
建议:上传多个collection的配置文件,建议修改配置文件名字,在solr.xml中按照文件名来引用collection对应的schema和solrconfig.xml文件,这样无论你多个coll ...
- MyBatis—实现关联表查询
一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 创建一张教师表和班级表,这里我们假设一个老师只负责教一个班,那么老师和班级之间的关系就是一种一对一的关 ...
- ajax load事件
ajax.load 使用ajax 来改变div元素文本. load( url [, data][, callback] ) load()方法的传递方式根据参数data来自动指定.如果没有参数传递,则 ...
- opencv3 图片模糊操作-均值滤波 高斯滤波 中值滤波 双边滤波
#include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...
- 661. Image Smoother色阶中和器
[抄题]: Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoo ...
- 【转】浏览器中F5和CTRL F5的行为区别
原文地址:http://www.cnblogs.com/jiji262/p/3410518.html 前言 在印象中,浏览器中的F5和刷新按钮是一样的效果,都是对当前页面进行刷新:Ctrl-F5的行为 ...
- C调用C++接口
在cpp头文件里面声明函数 #ifndef _HEAD_ #define _HEAD_ #ifdef __cplusplus extern "C" { #endif #define ...
- CentOS 安装mongodb3.0 二进制包
1.下载mongodb因为64位系统CentOS,所以下载64位的安装包: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0 ...
- 10.Execution failed with exit status: 3
错误信息: insert overwrite table t_mobile_mid_use_p_tmp4_rcf select '201411' as month_id, a.prov_id, a.c ...
- 用JS实现省市二级联动
一.需求分析 我们希望在注册页面中添加一个字段(籍贯),当用户选择一个具体的省份,在后面的下拉列表中动态加载该省份下所有的城市.显示的效果如下: 二.技术分析 使用事件(onchange) 使用一个二 ...