中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Spring Boot + Swagger 導出Pdf,Html

發布時間:2020-07-18 21:10:25 來源:網絡 閱讀:2452 作者:路遙o_o 欄目:編程語言

1. Maven 配置

    <dependency>
        <groupId>io.github.swagger2markup</groupId>
        <artifactId>swagger2markup</artifactId>
        <version>1.3.1</version>
    </dependency>

    <dependency>
        <groupId>nl.jworks.markdown_to_asciidoc</groupId>
        <artifactId>markdown_to_asciidoc</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>org.pegdown</groupId>
        <artifactId>pegdown</artifactId>
        <version>1.6.0</version>
        <scope>test</scope>
    </dependency>

2. plugin 配置

  <!--此插件生成ASCIIDOC-->
        <plugin>
            <groupId>io.github.swagger2markup</groupId>
            <artifactId>swagger2markup-maven-plugin</artifactId>
            <version>1.2.0</version>
            <configuration>
                <!--此處端口一定要是當前項目啟動所用的端口-->
                <swaggerInput>http://127.0.0.1:9092</swaggerInput>
                <outputDir>src/docs/asciidoc/generated</outputDir>
                <config>
                    <!-- 除了ASCIIDOC之外,還有MARKDOWN和CONFLUENCE_MARKUP可選 -->
                    <swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
                </config>
            </configuration>
        </plugin>

        <!--此插件生成HTML和PDF-->
        <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <version>1.5.3</version>
            <!-- Include Asciidoctor PDF for pdf generation -->
            <dependencies>
                <dependency>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctorj-pdf</artifactId>
                    <version>1.5.0-alpha.10.1</version>
                </dependency>
                <dependency>
                    <groupId>org.jruby</groupId>
                    <artifactId>jruby-complete</artifactId>
                    <version>1.7.21</version>
                </dependency>
            </dependencies>
            <!-- Configure generic document generation settings -->
            <configuration>
                <sourceDirectory>src/docs/asciidoc/generated</sourceDirectory>
                <sourceHighlighter>coderay</sourceHighlighter>
                <attributes>
                    <toc>left</toc>
                </attributes>
            </configuration>
            <!-- Since each execution can only handle one backend, run
                 separate executions for each desired output type -->
            <executions>
                <execution>
                    <id>output-html</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>process-asciidoc</goal>
                    </goals>
                    <configuration>
                        <backend>html5</backend>
                        <outputDirectory>src/docs/asciidoc/html</outputDirectory>
                    </configuration>
                </execution>

                <execution>
                    <id>output-pdf</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>process-asciidoc</goal>
                    </goals>
                    <configuration>
                        <backend>pdf</backend>
                        <outputDirectory>src/docs/asciidoc/pdf</outputDirectory>
                    </configuration>
                </execution>

            </executions>
        </plugin>

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

芦山县| 福贡县| 吴川市| 积石山| 方城县| 阜阳市| 张北县| 沈丘县| 墨玉县| 土默特左旗| 黄平县| 库伦旗| 新建县| 光泽县| 大足县| 龙州县| 剑河县| 武宣县| 东源县| 高要市| 九寨沟县| 乐至县| 会东县| 黄平县| 贵德县| 洪雅县| 高青县| 新民市| 田东县| 呼玛县| 民乐县| 济源市| 苗栗市| 连云港市| 凉城县| 蓝田县| 五原县| 清远市| 黄大仙区| 汝州市| 临桂县|