成都网站建设设计

将想法与焦点和您一起共享

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)
@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


文章名称:SpringBoot+Swagger导出Pdf,Html
转载注明:http://chengdu.cdxwcx.cn/article/ghieec.html