@XmlElement(required = true)
private String author;
@XmlElement(name = “price_1”, required = true)
private float price;
@XmlElement
private Date calendar;
@XmlAttribute
private Integer id;
/**
-
@return
*/
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public Date getCalendar() {
return calendar;
}
public void setCalendar(Date calendar) {
this.calendar = calendar;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return “Book [author=” + author + “, price=” + price + “, calendar=” + calendar + “, id=” + id + “]”;
}
}
(2)test
package com.guor.demo.beanToXml;
import java.util.Date;
import org.junit.Test;
import javax.xml.bind.JAXBException;
@SuppressWarnings(“unused”)
public class JaxbTest1 {
/**
- @throws JAXBException
*/
@Test
public void showMarshaller() {
Book book = new Book();
book.setId(100);
book.setAuthor(“lin”);
book.setCalendar(new Date());
book.setPrice(23.56f);
String str = JaxbUtil.converTomXml(book);
System.out.println(str);
}
/**
- @throws JAXBException<