將XML轉換為對象
/**
* xml转换成JavaBean
* @param xml
* @param c
* @return
*/
public static <T> T convertToJavaBean(String xml, Class<T> c) { if (StringUtils.isEmpty(xml)){
return null;
}
T t = null;
try {
JAXBContext context = JAXBContext.newInstance(c);
Unmarshaller unmarshaller = context.createUnmarshaller();
t = (T) unmarshaller.unmarshal(new StringReader(xml));
} catch (Exception e) {
log.error("xml to JavaBean ex.", e);
} return t;
}