XmlBeanMap convert

package com.yung.wx.integration.util;import com.thoughtworks.xstream.XStream;import com.yung.configuration.interceptor.XStreamFactory;import java.io.StringReader;import java.lang.reflect .Field;import java.util.HashMap;import java.util.List;import java.util.Map;import org.dom4j.Document;import org.dom4j.DocumentException;import org.dom4j.Element;import org.dom4j. io.SAXReader; public class XMLBeanUtil {private static final XStream xStream = XStreamFactory.getXStream(); /** * xml to object* @param xml xml string* @param bean bean * @param ignoreCase Whether to match case-insensitively* @return bean */ public static  T xmlToBean(String xml, T bean, boolean ignoreCase) {Map nodeMap = XMLBeanUtil.xmlToMap(xml); return mapToBean(nodeMap, bean, ignoreCase);} / ** * xml to object* @param xml xml string* @return Map */ public static Map xmlToMap(String xml) {try {SAXReader sax = new SAXReader();//Create a SAXReader object StringReader read = ne w StringReader(xml); Document document = sax.read(read);//Get the document object, if the document has no nodes, an Exception will be thrown to end early Element root = document.getRootElement();//Get the root node Map< String, String> nodeMap = new HashMap<>(); getNode(root, nodeMap); return nodeMap;} catch (DocumentException e) {return new HashMap<>();}} public static  T mapToBean(Map< String, String> map, T bean, boolean ignoreCase) {Field[] fields = bean.getClass().getDeclaredFields(); if (ignoreCase) {for (Field f: fields) {for (String k: map.keySet( )) {if (k.equalsIgnoreCase(f.getName())) {f.setAccessible(true); try {f.set(bean, map.get(k));} catch (IllegalAccessException ignore) {}}} }} else {for (Field f: fields) {for (String k: map.keySet()) {if (k.equals(f.getName())) {f.setAccessible(true); try {f.set (bean, map.get(k)); } catch (IllegalAccessException ignore) {}}}}} return bean;} private static void getNode(Element root, Map nodeMap) {List list = root.elements(); for (Element e: list) {if ("".equals(e.getTextTrim())) {getNode(e, nodeMap);} else {nodeMap.put(e.getName(), e.getTextTrim());}}} /* * * Object to xml * @param obj object* @return String */ public static String toXml(Object obj) {xStream.processAnnotations(obj.getClass()); return xStream.toXML(obj); })

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 6021 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.