我不确定您是如何配置jaxb上下文或marshaller的,但是:
public static void main(String[] args) throws Exception
{
Employee employee = new Employee();
employee.setId(1);
employee.setName("Ralph");
JAXBContext context = JAXBContext.newInstance(Employee.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(employee, System.out);
}
给出:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee>
<name>Ralph</name>
<id>1</id>
</employee>