html文档生成pdf离线文件,SringBoot+Swagger2导出pdf离线文档

本文档介绍了如何在SpringBoot项目中利用Swagger2导出离线API文档。首先,你需要运行一个测试类生成ASCII格式的文档,然后在pom.xml中配置相关依赖和插件,设置你的项目URL。接着,执行`mvn asciidoctor:process-asciidoc`和`mvn generate-resources`两个Maven指令,最终在`src/docs`目录下会生成离线文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在SpringBoot项目中使用了Swagger2可以使用以下办法导出离线文件

首先将下面代码拷贝到你的项目中测试运行(必须要先运行这个测试类)

注意:要修改成你的URL地址

@RunWith(SpringRunner.class)

public class ExportConfig {

@Test

public void generateAsciiDocs() throws Exception {

// 输出Ascii格式

Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withMarkupLanguage(MarkupLanguage.ASCIIDOC)

.withOutputLanguage(Language.ZH).withPathsGroupedBy(GroupBy.TAGS).withGeneratedExamples()

.withoutInlineSchema().build();

Swagger2MarkupConverter.from(new URL("http://172.21.3.15:8080/v2/api-docs")).withConfig(config)

.build().toFolder(Paths.get("src/docs/asciidoc/generated"));

}

}

然后在pom.xml中导入需要的一些依赖和插件

依赖

io.github.swagger2markup

swagger2markup

1.3.3

插件:插件中需要像上面那个测试代码一样修改成你的项目IP和端口

springboot-swagger

io.github.swagger2markup

swagger2markup-maven-plugin

1.2.0

http://localhost:8080/v2/api-docs

src/docs/asciidoc/generated

ASCIIDOC

org.asciidoctor

asciidoctor-maven-plugin

1.5.3

org.asciidoctor

asciidoctorj-pdf

1.5.0-alpha.10.1

org.jruby

jruby-complete

1.7.24

src/docs/asciidoc/generated

coderay

left

output-html

generate-resources

process-asciidoc

html5

src/docs/asciidoc/html

output-pdf

generate-resources

process-asciidoc

pdf

src/docs/asciidoc/pdf

org.eclipse.m2e

lifecycle-mapping

1.0.0

org.asciidoctor

asciidoctor-maven-plugin

[1.5.3,)

process-asciidoc

最后依次执行这两条mvn指令:mvn asciidoctor:process-asciidoc 和 mvn generate-resources

然后就可以在项目的src\docs目录下看到你需要的离线文档了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值