继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

把JavaBean---->XML 学习笔记

萌萌小温柔
关注TA
已关注
手记 306
粉丝 56
获赞 401

import java.util.ArrayList;import java.util.List;import org.junit.Test;import com.thoughtworks.xstream.XStream;//把JavaBean---->XMLpublic class XStreamDemo {    @Test    public void test1(){        Product p = new Product(1, "×××", 20);        XStream xs = new XStream();        //指定别名        xs.alias("product", Product.class);        String xml = xs.toXML(p);        System.out.println(xml);    }    @Test    public void test2(){        List<Product> products = new ArrayList<Product>();        products.add(new Product(1, "充气筒", 20));        products.add(new Product(2, "×××", 10));        products.add(new Product(3, "袜子", 10));        products.add(new Product(4, "洗衣粉", 10));        products.add(new Product(5, "肥皂", 7));        XStream xs = new XStream();        //指定别名        xs.alias("products", List.class);        xs.alias("product", Product.class);        String xml = xs.toXML(products);        System.out.println(xml);    }}

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP