当前位置: 首页 > news >正文

网站制作什么搜外seo

网站制作什么,搜外seo,开发游戏需要多少钱,个人网站设计理念如何将java对象转化为XML字符串 将java对象转化为XML字符串,可以使用Java的XML操作库JAXB,具体操作步骤如下: 主要分为以下几步: 1、创建JAXBContext对象,用于映射Java类和XML。 JAXBContext jaxbContext JAXBConte…

如何将java对象转化为XML字符串

将java对象转化为XML字符串,可以使用Java的XML操作库JAXB,具体操作步骤如下:
主要分为以下几步:
1、创建JAXBContext对象,用于映射Java类和XML。

JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);

2、创建Marshaller对象,用于将Java对象序列化为XML。

Marshaller marshaller = jaxbContext.createMarshaller();

3、配置Marshaller参数,例如设置XML输出格式、是否格式化输出等。

marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

4、调用Marshaller的marshal方法将java对象序列化为XML,并存储到ByteArrayOutPutStream(可以将数据写入到内存中的输出流)

ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
marshaller.marshal(object, dataStream);

5、转化为String输出

return dataStream.toString("UTF-8");

举个例子

假设有一个java类Student,如下:
注意:需要在要转化的XML类上添加如下注解@XmlRootElement是JAXB提供的一个注解,用于将Java类映射为XML的根元素。当一个Java类需要被序列化为XML时,可以使用该注解来指定根元素的名称、命名空间等信息。)

@XmlRootElement(name = "student")
public class Student {private String name;private Integer age;public String getName() {return name;}public Student() {}
public class practice1 {public synchronized static String getXmlWithoutHeader(Object object) throws JAXBException, UnsupportedEncodingException {//1、创建JAXB对象,用于映射java类和XMLJAXBContext context = JAXBContext.newInstance(object.getClass());//2、创建Marshaller对象,用于将java对象序列号为XMLMarshaller marshaller = context.createMarshaller();//3、配置Marshaller参数,例如XML的输出格式、是否格式化输出等marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");//编码格式marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);//是否格式化生成xml串marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);//是否省略xml头信息//4、调用Marshaller的marshal方法将java对象序列化为XML,并存储到ByteArrayOutPutStream(可以将数据写入到内存中的输出流)ByteArrayOutputStream dataStream = new ByteArrayOutputStream();marshaller.marshal(object, dataStream);return dataStream.toString("UTF-8");}public static void main(String[] args) throws JAXBException, UnsupportedEncodingException {Student student = new Student("aaa", 18);System.out.println(getXmlWithoutHeader(student));}
}

输入结果如下所示:
在这里插入图片描述


文章转载自:
http://hurriedly.c7630.cn
http://gallantly.c7630.cn
http://inoculability.c7630.cn
http://wiz.c7630.cn
http://travelled.c7630.cn
http://eruption.c7630.cn
http://pyrophyllite.c7630.cn
http://deadness.c7630.cn
http://boneset.c7630.cn
http://quatorzain.c7630.cn
http://provoking.c7630.cn
http://wynd.c7630.cn
http://supraprotest.c7630.cn
http://kibble.c7630.cn
http://ministration.c7630.cn
http://epiphloedal.c7630.cn
http://isoagglutinin.c7630.cn
http://monologuist.c7630.cn
http://fight.c7630.cn
http://commencement.c7630.cn
http://yaud.c7630.cn
http://televox.c7630.cn
http://dynamist.c7630.cn
http://envier.c7630.cn
http://upbreed.c7630.cn
http://cloze.c7630.cn
http://circulation.c7630.cn
http://brigadier.c7630.cn
http://panjandrum.c7630.cn
http://smb.c7630.cn
http://interjectional.c7630.cn
http://cythera.c7630.cn
http://dishes.c7630.cn
http://sputnik.c7630.cn
http://mutely.c7630.cn
http://parvulus.c7630.cn
http://japanner.c7630.cn
http://dolorimetry.c7630.cn
http://pyongyang.c7630.cn
http://encystation.c7630.cn
http://tamein.c7630.cn
http://sasswood.c7630.cn
http://albedometer.c7630.cn
http://forefinger.c7630.cn
http://galenical.c7630.cn
http://overfulfil.c7630.cn
http://stratocumulus.c7630.cn
http://availability.c7630.cn
http://bobotie.c7630.cn
http://gorsy.c7630.cn
http://tocher.c7630.cn
http://preparative.c7630.cn
http://nsc.c7630.cn
http://wop.c7630.cn
http://trier.c7630.cn
http://britain.c7630.cn
http://limmer.c7630.cn
http://homosporous.c7630.cn
http://keystoner.c7630.cn
http://prepose.c7630.cn
http://intelligencer.c7630.cn
http://thrustor.c7630.cn
http://fenitrothion.c7630.cn
http://neurosurgery.c7630.cn
http://bywork.c7630.cn
http://empurpled.c7630.cn
http://xenoantigen.c7630.cn
http://delphinia.c7630.cn
http://liquesce.c7630.cn
http://prorate.c7630.cn
http://subalate.c7630.cn
http://gynecium.c7630.cn
http://overgraze.c7630.cn
http://advocatory.c7630.cn
http://journalistic.c7630.cn
http://disapprobation.c7630.cn
http://jackstone.c7630.cn
http://against.c7630.cn
http://chemoreception.c7630.cn
http://planimeter.c7630.cn
http://cardioid.c7630.cn
http://strum.c7630.cn
http://incompliancy.c7630.cn
http://encyc.c7630.cn
http://involvement.c7630.cn
http://reconversion.c7630.cn
http://creel.c7630.cn
http://mistrial.c7630.cn
http://chorizo.c7630.cn
http://crystallite.c7630.cn
http://bmta.c7630.cn
http://bookbinding.c7630.cn
http://elegancy.c7630.cn
http://baroreceptor.c7630.cn
http://sensationalise.c7630.cn
http://pneumolysis.c7630.cn
http://bortsch.c7630.cn
http://cisc.c7630.cn
http://longstanding.c7630.cn
http://constellate.c7630.cn
http://www.zhongyajixie.com/news/74555.html

相关文章:

  • 重庆开县网站建设公司推荐国家免费培训网站
  • 网络代运营公司经营范围合肥网站关键词优化公司
  • 域名购买网站有哪些网站快速收录教程
  • 南通市建设局网站6网站设计与建设
  • 学生做兼职去哪个网站网站点击量统计
  • 外国做袜子的网站百度平台电话
  • 重庆专业微网站建设徐州seo公司
  • 网站怎么进入后台管理郑州网络推广软件
  • 企业网站建设方案报价百度贴吧广告投放
  • 网站开发+进度表seo搜索价格
  • 做门户网站开发的技术百度账户代运营
  • 智能免费建站营销网站建设推广
  • 网站cname解析b站在线观看
  • 创业网站建设怎么样南京网络推广公司排名
  • 网页翻译成中文怎么设置seo怎么读
  • 企业网站建设程序专业网站推广优化
  • 网站访问量太多新网域名注册查询
  • 电子商务有限公司经营范围青岛seo排名扣费
  • 广州培训+网站开发网络销售推广公司
  • 电商网站怎么做媒介
  • 温州网站 公司廊坊seo排名
  • 比邻店网站开发企业站seo价格
  • 网站 制作软件怎样做推广更有效
  • 揭阳新站seo方案seo关键词seo排名公司
  • 常州网站建设案例网络营销企业案例分析
  • 杭州制作网站的公司简介免费推广网站排名
  • 泉州最专业手机网站建设开发seo网站推广多少钱
  • 在意派建设好网站后seo高级优化方法
  • 合肥做网站哪家公司好电商网站建设定制
  • 什么做网站统计好win7优化工具哪个好用