Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何更改对象上JAXB deppending中XmlRootElement的名称?_Java_Jaxb - Fatal编程技术网

Java 如何更改对象上JAXB deppending中XmlRootElement的名称?

Java 如何更改对象上JAXB deppending中XmlRootElement的名称?,java,jaxb,Java,Jaxb,我有以下对象 胶卷 当我通过JAXB运行它时,我得到: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <film fbId="1"> <description>Nice film</description> <person fbId="1"> <firstName>Quentin</firstName>

我有以下对象

胶卷

当我通过JAXB运行它时,我得到:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<film fbId="1">
    <description>Nice film</description>
    <person fbId="1">
        <firstName>Quentin</firstName>
        <lastName>Tarantino</lastName>
    </person>
    <performace>
        <person fbId="4">
            <firstName>Steve</firstName>
            <lastName>Buscemi</lastName>
        </person>
        <character>Billy</character>
    </performace>
    <performace>
        <person fbId="2">
            <firstName>Jhon</firstName>
            <lastName>Travolta</lastName>
        </person>
        <character>Vincent</character>
    </performace>
    <performace>
        <person fbId="3">
            <firstName>Samuel</firstName>
            <lastName>L Jackson</lastName>
        </person>
        <character>Jules</character>
    </performace>
    <performace>
        <person fbId="1">
            <firstName>Quentin</firstName>
            <lastName>Tarantino</lastName>
        </person>
        <character>Jimmie</character>
    </performace>
    <title>Pulp Fiction</title>
</film>

好电影
昆廷
塔伦蒂诺
史蒂夫
布谢米
比利
约翰
特拉沃尔塔
文森特
塞缪尔
杰克逊
朱尔斯
昆廷
塔伦蒂诺
吉米
低俗小说
有没有办法改变“人”的名字?要得到这样的东西:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<film fbId="1">
    <description>Nice film</description>
    <director fbId="1">
        <firstName>Quentin</firstName>
        <lastName>Tarantino</lastName>
    </director>
    <performace fbId="4">
        <firstName>Steve</firstName>
        <lastName>Buscemi</lastName>
        <character>Billy</character>
    </performace>
    <performace fbId="2">
        <firstName>Jhon</firstName>
        <lastName>Travolta</lastName>
        <character>Vincent</character>
    </performace>
    <performace fbId="3">
        <firstName>Samuel</firstName>
        <lastName>L Jackson</lastName>
        <character>Jules</character>
    </performace>
    <performace fbId="1">
        <firstName>Quentin</firstName>
        <lastName>Tarantino</lastName>
        <character>Jimmie</character>
    </performace>
    <title>Pulp Fiction</title>
</film>

好电影
昆廷
塔伦蒂诺
史蒂夫
布谢米
比利
约翰
特拉沃尔塔
文森特
塞缪尔
杰克逊
朱尔斯
昆廷
塔伦蒂诺
吉米
低俗小说
选项:

  • Make
    Director
    使用自己的
    @XmlRootElement
  • 对“xmlementrefs”使用
    JAXBElementThanks,我已经解决了这个问题。我已经搞定导演了。。。谢谢
    
    @Entity
    @Table(name="performance")
    @XmlRootElement(name = "performace")
    public class Performance implements Serializable {
    
        @Id
        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="film")
        private Film film;
    
        @Id
        @Column(name="film_character")
        private String character;
    
        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="actor")
        private Person actor;
    
        //TO STRING
        public String toString() {
            return this.actor.toString() + " - " + this.character;
        }
    
        //GETTERS
        @XmlTransient
        public Film getFilm() {
            return this.film;
        }
    
        @XmlElementRefs({
            @XmlElementRef(name = "firstName", type = Person.class),
            @XmlElementRef(name = "lastName", type = Person.class)
        })
        public Person getActor() {
            return this.actor;
        }
    
        @XmlElement(name = "character")
        public String getCharacter() {
            return this.character;
        }
    
    }
    
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <film fbId="1">
        <description>Nice film</description>
        <person fbId="1">
            <firstName>Quentin</firstName>
            <lastName>Tarantino</lastName>
        </person>
        <performace>
            <person fbId="4">
                <firstName>Steve</firstName>
                <lastName>Buscemi</lastName>
            </person>
            <character>Billy</character>
        </performace>
        <performace>
            <person fbId="2">
                <firstName>Jhon</firstName>
                <lastName>Travolta</lastName>
            </person>
            <character>Vincent</character>
        </performace>
        <performace>
            <person fbId="3">
                <firstName>Samuel</firstName>
                <lastName>L Jackson</lastName>
            </person>
            <character>Jules</character>
        </performace>
        <performace>
            <person fbId="1">
                <firstName>Quentin</firstName>
                <lastName>Tarantino</lastName>
            </person>
            <character>Jimmie</character>
        </performace>
        <title>Pulp Fiction</title>
    </film>
    
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <film fbId="1">
        <description>Nice film</description>
        <director fbId="1">
            <firstName>Quentin</firstName>
            <lastName>Tarantino</lastName>
        </director>
        <performace fbId="4">
            <firstName>Steve</firstName>
            <lastName>Buscemi</lastName>
            <character>Billy</character>
        </performace>
        <performace fbId="2">
            <firstName>Jhon</firstName>
            <lastName>Travolta</lastName>
            <character>Vincent</character>
        </performace>
        <performace fbId="3">
            <firstName>Samuel</firstName>
            <lastName>L Jackson</lastName>
            <character>Jules</character>
        </performace>
        <performace fbId="1">
            <firstName>Quentin</firstName>
            <lastName>Tarantino</lastName>
            <character>Jimmie</character>
        </performace>
        <title>Pulp Fiction</title>
    </film>
    
    @XmlElementRefs({
        @XmlElementRef(name = "firstName", type = Person.class),
        @XmlElementRef(name = "lastName", type = Person.class)
    })