以下配置意味着什么(jaxb-fluent-api)?

use*_*403 5 java spring web-services jax-ws jaxb

我的POM文件中有以下配置.特别是jaxb-fluent-api配置.

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <configuration>
        <extension>true</extension>
        <args>
            <arg>-Xfluent-api</arg>
        </args>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <plugins>
            <plugin>
                <groupId>net.java.dev.jaxb2-commons</groupId>
                <artifactId>jaxb-fluent-api</artifactId>
                <version>2.1.8</version>
            </plugin>
        </plugins>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

如果不配置jaxb-fluent-api,可以从xsd生成实体.这里使用jaxb-fluent-api的好处是什么?

谢谢!

npe*_*npe 9

jaxb-fluent-api是一个JAXB扩展,允许您以流畅的api风格生成代码.现在,流畅的api是一种设计类方法的方法,因此它们总是返回this而不是void.

项目维基上有一个很好的例子(为简洁起见我稍微缩短了一点,访问网站以获得完整示例):

JAXB必须使用正常生成的代码,如下所示:

Project project = factory.createProject();

project.setModelVersion("4.0.0");
project.setGroupId("redmosquito")
project.setArtifactId("jaxb-fluent-api-ext")
project.setPackaging("jar")
project.setVersion("0.0.1")
project.setName("JAXB Fluent API Extensions");
Run Code Online (Sandbox Code Playgroud)

通过jaxb-fluent-api扩展,您可以像这样对上面的代码进行编码:

Project project = factory.createProject()
    .withModelVersion("4.0.0");
    .withGroupId("redmosquito")
    .withArtifactId("jaxb-fluent-api-ext")
    .withPackaging("jar")
    .withVersion("0.0.1")
    .withName("JAXB Fluent API Extensions");
Run Code Online (Sandbox Code Playgroud)

这基本上就是流利的api的全部内容.