gpt4 book ai didi

java - 设置hyperjaxb映射强制实现外部接口(interface)

转载 作者:行者123 更新时间:2023-11-30 10:56:25 25 4
gpt4 key购买 nike

我有一个 hyperjaxb xsd 文件和绑定(bind)配置。如何强制我生成的类实现在另一个 Artifact 中声明的自定义接口(interface)?我知道我可以让他们通过使用扩展另一个类

    <xjc:superClass name="com.sample.jpa.entities.BaseEntity"/>

但我还需要它们实现另一个接口(interface)。我怎样才能做到这一点?

最佳答案

免责声明: Hyperjaxb 的作者和 JAXB2-Basics在这里。

您可以使用 Inheritance plugin来自 JAXB2-Basics连同 Hyperjaxb .您既可以扩展一个类,也可以实现一个接口(interface)。该插件还可以处理泛型,因此您甚至可以执行类似 <inheritance:implements>com.acme.foo.MyInterface&lt;com.acme.foo.SomeClass&gt;</inheritance:implements> 的操作。 .

简短指南:

  • 通过<arg>-Xinheritance</arg>启用插件在你的pom.xml .像这样的东西:

        <plugin>
    <groupId>org.jvnet.hyperjaxb3</groupId>
    <artifactId>maven-hyperjaxb3-plugin</artifactId>
    <configuration>
    <!--result>mappingFiles</result-->
    <roundtripTestClassName>org.jvnet.hyperjaxb3.ejb.tests.cuone.RoundtripTest</roundtripTestClassName>
    <args>
    <arg>-Xinheritance</arg>
    </args>
    </configuration>
    </plugin>

    JAXB2-Basics 是 Hyperjaxb 的依赖项,因此您很可能不需要在此处执行任何其他操作。查看example (对于注释插件,但这并不重要)。

  • 使用 inheritance:extends 自定义您的复杂类型或 inheritance:implements定制元素。示例:

    <jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
    <jaxb:bindings node="xsd:complexType[@name='WillBeMadeCloneableType']">
    <inheritance:implements>java.lang.Cloneable</inheritance:implements>
    </jaxb:bindings>
    </jaxb:bindings>

应该是这样吧。

关于java - 设置hyperjaxb映射强制实现外部接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33024067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com