1、pom文件新增restdocs

<dependency>   
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>   
<scope>test</scope>
</dependency>
<plugin>   
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>   
<version>1.5.8</version>   
<executions>       
<execution>           
<id>generate-docs</id>           
<phase>prepare-package</phase>           
<goals>               
<goal>process-asciidoc</goal>           
</goals>           
<configuration>               
<backend>html</backend>               
<doctype>book</doctype>           
</configuration>       
</execution>   
</executions>   
<dependencies>       
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>   
</dependencies>
</plugin>

2、在test包下新建controller

@RunWith(SpringRunner.class)
@SpringBootTestpublic class ApiBaseController {    @Rule   
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();    public MockMvc mockMvc;    @Autowired   
private WebApplicationContext context;    @Before   
public void setUp() {       
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation))
.build();   
}
}

3、新建单元测试

public class TestController extends ApiBaseController {
@Test   
public void test() throws Exception {       
super.mockMvc.perform(post("/test").param("aaa", "bbb")               
.contentType(MediaType.APPLICATION_JSON))               
.andDo(document("{ClassName}/{methodName}",
preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()),                       
requestParameters(parameterWithName("aaa").description("查询名字"))));   
}
}

4、运行后会在target\generated-snippets生成adoc文件

5、在main下新建asciidoc包,新建index.adoc 拼接已经生成的adoc

= API:toc:
left:toclevels: 4
[[order-it]]
== 1. 订单接口
[[order-query]]
=== 订单查询
operation::TestController/test[snippets='curl-request,http-request']

springboot集成restdocs输出接口文档的更多相关文章

  1. SpringBoot集成Swagger2在线文档

    目录 SpringBoot集成Swagger2在线文档 前言 集成SpringBoot 登录接口文档示例 代码 效果 注解说明 总结 SpringBoot集成Swagger2在线文档 前言 不得不说, ...

  2. SpringBoot 如何生成接口文档,老鸟们都这么玩的!

    大家好,我是飘渺. SpringBoot老鸟系列的文章已经写了两篇,每篇的阅读反响都还不错,果然大家还是对SpringBoot比较感兴趣.那今天我们就带来老鸟系列的第三篇:集成Swagger接口文档以 ...

  3. springboot使用swagger2创建文档

    一.导入swagger2依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>spri ...

  4. Springboot+swagger2的接口文档开发

    一.创建一个SpringBoot项目 1. 2. 3. 4. 把web里的web选中,SQL里选择自己需要的,点击next 二.创建各项所需的controller,configure等 1. 项目布局 ...

  5. SpringCloud微服务实战——搭建企业级开发框架(六):使用knife4j集成Swagger2接口文档

    knife4j是为集成Swagger生成api文档的增强解决方案,前后端Java代码以及前端Ui模块进行分离,在微服务架构下使用更加灵活, 提供专注于Swagger的增强解决方案,不同于只是改善增强前 ...

  6. Springboot swagger2 导出api文档

    具体导出的代码,参考了:http://www.spring4all.com/article/699 导出前,首先需要配置好swagger2,参见 https://www.cnblogs.com/yan ...

  7. springboot + swagger2 生成api文档

    直接贴代码: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...

  8. SpringBoot+FreeMarker开发word文档下载,预览

    背景: 开发一个根据模版,自动填充用户数据并下载word文档的功能 使用freemarker进行定义模版,然后把数据进行填充. maven依赖: <parent> <groupId& ...

  9. spring-boot+swagger实现WebApi文档

    1.引用依赖包 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-s ...

随机推荐

  1. Js中“==”和“===”的区别

    从字面上来讲,‘==’代表相等,‘===’代表严格相等. 具体来讲,比较过程如下: 比较过程: ‘==’:      1. 首先判断两个值的类型是否相同,如果相同,进行‘===’判断.      2. ...

  2. vue组件中data是个函数

    当我们const vm = new Vue({ el : '#app',   data : { msg:‘hello World’ } })用习惯了,data是一个对象,可到了vue组件 Vue.co ...

  3. 超容易理解的call()、apply()、bind()的区别

    call().apply().bind()是用来改变this的指向的. 一 举个例子 一个叫喵喵的猫喜欢吃鱼,一个叫汪汪的小狗喜欢啃骨头,用代码实现如下: 有一天,小狗汪汪和喵喵共进午餐的时候,汪汪说 ...

  4. 洪强宁:宜信PaaS平台基于Calico的容器网络实践

    洪强宁:宜信PaaS平台基于Calico的容器网络实践   本文内容来自由七牛云主办的ECUG Con,独家授权InfoQ整理完成 容器云面临的网络挑战 在传统的IDC的架构里面网络是很重要的事情,在 ...

  5. Servlet学习笔记(一)

    使用Servlet所需要导入的包: java.io.*;                                                 javax.servlet.*;       ...

  6. ASP.NET WebForm Identity使用

    环境 win10企业版x64+visual studio 2017+.net 4.5 step1 基本使用+邮件确认+密码重置 https://docs.microsoft.com/en-us/asp ...

  7. Channel 9视频整理【3】

    Will 保哥 微软mvp https://channel9.msdn.com/Niners/Will_Huang 繁体中文视频 Visual Studio 2017 新功能探索 https://ch ...

  8. Github安装和使用(超级详细)

    Github (原创:黑小子-余) 小编我是一名Git新手,然后花三天时间通过查找网上资料,了解Git的简单使用.本次我就实战操作git安装.github仓库创建.上传代码到github上.从gith ...

  9. DRF框架中的异常处理程序

    目录 DRF框架中自定义异常处理 一.自定义异常的原因 二.如何设置处理异常的程序 DRF框架中自定义异常处理 一.自定义异常的原因 在Django和DRF框架中都封装了很多的处理异常的程序,可以处理 ...

  10. Python+appium+unittest UI自动化测试

    什么是UI自动化 自动化分层 单元自动化测试,指对软件中最小可测试单元进行检查和验证,一般需要借助单元测试框架,如java的JUnit,python的unittest等 接口自动化测试,主要检查验证模 ...