將XML轉換為對象
1 /**
2 * xml转换成JavaBean
3 * @param xml
4 * @param c
5 * @return
6 */
7 public static <T> T convertToJavaBean(String xml, Class<T>
c) {
8
9 if (StringUtils.isEmpty(xml)){
10 return null;
11 }
12 T t =
null;
13 try {
14 JAXBContext context =
JAXBContext.newInstance(c);
15 Unmarshaller unmarshaller =
context.createUnmarshaller();
16 t = (T) unmarshaller.unmarshal(
new StringReader(xml));
17 }
catch (Exception e) {
18 log.error("xml to JavaBean ex."
, e);
19 }
20
21 return t;
22 }
转载于:https://www.cnblogs.com/javallh/p/9936062.html
相关资源:JavaBean 转换为xml的三种方式比较