SpringBoot+Swagger导出Pdf,Html-创新互联
1. Maven 配置
io.github.swagger2markup
swagger2markup
1.3.1
nl.jworks.markdown_to_asciidoc
markdown_to_asciidoc
1.0
org.pegdown
pegdown
1.6.0
test
2. plugin 配置
io.github.swagger2markup
swagger2markup-maven-plugin
1.2.0
http://127.0.0.1:9092
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.21
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
3.新建GneratorSwaggerPdfAndHtml --- UT
@RunWith(SpringRunner.class)
创新互联是一家专注于成都网站建设、成都网站制作与策划设计,碑林网站建设哪家好?创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:碑林等地区。碑林做网站价格咨询:13518219792
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class GneratorSwaggerPdfAndHtml {
public void generateAsciiDocs() throws Exception {
// 输出Ascii格式
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withMarkupLanguage(MarkupLanguage.ASCIIDOC)
.build();
Swagger2MarkupConverter.from(new URL("http://localhost:9092/v2/api-docs"))
.withConfig(config)
.build()
.toFolder(Paths.get("src/docs/asciidoc/generated"));
}
}
4. Swagger2AutoConfiguration 配置
本地 Swagger2AutoConfiguration类,继承WebMvcConfigurationSupport,并重写addResourceHandlers方法
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
5.编译命令生成PDF,Html
先执行命令mvn asciidoctor:process-asciidoc
Run 此UT,会生成Adoc文件。
然后执行 命令mvn generate-resources
生成PDF和HTML
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
当前文章:SpringBoot+Swagger导出Pdf,Html-创新互联
URL地址:http://pwwzsj.com/article/dhgess.html