欢迎来到Heck's Blog,专业承接拿站、企业建站、仿站、网上商城架构、门户网站搭建、空间域名注册、软件定制等项目。关注网络安全,因为专注,所以专业,懂得放弃,才能收获。有事请发邮件至i@heckjj.com,请记住本站网址:http://www.heckjj.com,多谢。
11月6
前几天在书上看的,实验了一下,结果还不错,收藏下来:
package com;
import java.util.*;
import net.sf.json.JSONObject;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class ExtHelper {
public static String getXmlFormList(long recordTotal,List beanList){
Total total = new Total(); //保存记录总数
total.setResults(recordTotal); //设置记录总数到 total对象
List results = new ArrayList(); //创建临时的 List 对象 results
results.add(total); // 添加对象
results.addAll(beanList); // 追加对象
XStream sm = new XStream(new DomDriver()); //创建Xstream对象
for(int i=0;i<results.size();i++){
Class c = results.get(i).getClass();
String b = c.getName();
String[] temp = b.split("\\.");
sm.alias(temp[temp.length-1],c);
}
String xml = "<?xml version='1.0' encoding='UTF-8'?>"+sm.toXML(results);
return xml;
}
package com;
import java.util.*;
import net.sf.json.JSONObject;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class ExtHelper {
public static String getXmlFormList(long recordTotal,List beanList){
Total total = new Total(); //保存记录总数
total.setResults(recordTotal); //设置记录总数到 total对象
List results = new ArrayList(); //创建临时的 List 对象 results
results.add(total); // 添加对象
results.addAll(beanList); // 追加对象
XStream sm = new XStream(new DomDriver()); //创建Xstream对象
for(int i=0;i<results.size();i++){
Class c = results.get(i).getClass();
String b = c.getName();
String[] temp = b.split("\\.");
sm.alias(temp[temp.length-1],c);
}
String xml = "<?xml version='1.0' encoding='UTF-8'?>"+sm.toXML(results);
return xml;
}





