You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
538 B
Java
28 lines
538 B
Java
4 years ago
|
package com.manage.util;
|
||
|
|
||
|
|
||
|
import org.simpleframework.xml.Serializer;
|
||
|
import org.simpleframework.xml.core.Persister;
|
||
|
|
||
|
import javax.xml.bind.JAXBException;
|
||
|
|
||
|
public class XmlUtil {
|
||
|
|
||
|
/**
|
||
|
* 字符串转xml
|
||
|
*/
|
||
|
public static <T> T xmlToEntity(Class<T> clazz, String str) {
|
||
|
try {
|
||
|
Serializer serializer = new Persister();
|
||
|
T entity = serializer.read(clazz, str);
|
||
|
return entity;
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|