英文:
Problem with building Xml with Java (Jaxb)
问题
所以我想要构建一个 XML 文档。当我尝试编译它时,在这个文件(第23、24、30、31行)中会出现错误。错误消息是:类型的非法开始。
package legoset;
import lombok.Data;
import movie.YearAdapter;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.net.URL;
import java.time.Year;
import java.util.List;
import java.util.Set;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = "name", "theme", "subtheme", "year", "pieces")
@Data
public class LegoSet {
private String name;
private String theme;
private String subtheme;
private int pieces;
@XmlElementWrapper(name = "minifigs")
@XmlElement(name = "minifig")
private List<Minifig> minifigs;
private Weight weight;
private URL url;
@XmlElementWrapper(name = "tags")
@XmlElement(name = "tag")
private Set<String> tags;
@XmlJavaTypeAdapter(YearAdapter.class)
private Year year;
@XmlAttribute
private String number;
}
英文:
So I want to build an Xml document. When I try to compile it drops error in this file (line 23, 24, 30, 31). The error message is: illegal start of type.
package legoset;
import lombok.Data;
import movie.YearAdapter;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.net.URL;
import java.time.Year;
import java.util.List;
import java.util.Set;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = "name", "theme", "subtheme", "year", "pieces")
@Data
public class LegoSet {
private String name;
private String theme;
private String subtheme;
private int pieces;
@XmlElementWrapper(name = "minifigs");
@XmlElement(name = "minifig");
private List<Minifig> minifigs;
private Weight weight;
private URL url;
@XmlElementWrapper(name = "tags");
@XmlElement(name = "tag");
private Set<String> tags;
@XmlJavaTypeAdapter(YearAdapter.class)
private Year year;
@XmlAttribute
private String number;
}
答案1
得分: 0
请删除注释后的分号。
例如:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = "name", "theme", "subtheme", "year", "pieces")
@Data
public class LegoSet {
private String name;
private String theme;
private String subtheme;
private int pieces;
@XmlElementWrapper(name = "minifigs")
@XmlElement(name = "minifig")
private List<Minifig> minifigs;
private Weight weight;
private URL url;
@XmlElementWrapper(name = "tags")
@XmlElement(name = "tag")
private Set<String> tags;
@XmlJavaTypeAdapter(YearAdapter.class)
private Year year;
@XmlAttribute
private String number;
}
英文:
Remove the semicolon after annotation.
e.g.
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = "name", "theme", "subtheme", "year", "pieces")
@Data
public class LegoSet {
private String name;
private String theme;
private String subtheme;
private int pieces;
@XmlElementWrapper(name = "minifigs")
@XmlElement(name = "minifig")
private List<Minifig> minifigs;
private Weight weight;
private URL url;
@XmlElementWrapper(name = "tags")
@XmlElement(name = "tag")
private Set<String> tags;
@XmlJavaTypeAdapter(YearAdapter.class)
private Year year;
@XmlAttribute
private String number;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论