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

专门做cos的网站网站排行榜前十名

专门做cos的网站,网站排行榜前十名,中山祥云做的网站,网站建设仪器配置表现在有一个实体类对象的集合&#xff0c;需要将它们转换为xml文档&#xff0c;xml文档就是标签集合的嵌套&#xff0c;例如一个学生类&#xff0c;有姓名、年龄等&#xff0c;需要转换成一下效果&#xff1a; <student><age>14</age><name>张三</na…

现在有一个实体类对象的集合,需要将它们转换为xml文档,xml文档就是标签集合的嵌套,例如一个学生类,有姓名、年龄等,需要转换成一下效果:

 <student><age>14</age><name>张三</name></student><student><age>15</age><name>李四</name></student><student><age>16</age><name>王五</name></student>

首先定义student的实体类:

import lombok.Data;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;@Data
@XmlRootElement
public class Student {private String name;private int age;// 无参构造函数(必须有)public Student() {}public Student(String name, int age) {this.name = name;this.age = age;}@XmlElementpublic String getName() {return name;}public void setName(String name) {this.name = name;}@XmlElementpublic int getAge() {return age;}public void setAge(int age) {this.age = age;}
}

因为是student的集合,需要再构建一个StudentListWrapper类:

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;@XmlRootElement
public class StudentListWrapper {private List<Student> students;public StudentListWrapper() {}public StudentListWrapper(List<Student> students) {this.students = students;}@XmlElement(name = "student")public List<Student> getStudents() {return students;}public void setStudents(List<Student> students) {this.students = students;}
}

两种下载方式:无返回值的:

 @GetMapping("testXmlDownload")public void testXmlDownload(HttpServletResponse response) throws Exception {try {// 创建一个包含 Student 对象的集合List<Student> studentList = new ArrayList<>();studentList.add(new Student("张三", 14));studentList.add(new Student("李四", 15));studentList.add(new Student("王五", 16));// 创建 JAXB 上下文JAXBContext context = JAXBContext.newInstance(StudentListWrapper.class);// 创建 MarshallerMarshaller marshaller = context.createMarshaller();marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);// 将集合序列化为 XMLStringWriter writer = new StringWriter();marshaller.marshal(new StudentListWrapper(studentList), writer);// 输出 XML 格式的文档String xmlDocument = writer.toString();byte[] bytes = xmlDocument.getBytes();// 使用 ByteArrayInputStream 将字节数组转换为 InputStreamInputStream inputStream = new ByteArrayInputStream(bytes);// 使用 BufferedInputStream 包装 InputStreamBufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);byte[] buffer = new byte[bufferedInputStream.available()];bufferedInputStream.read(buffer);bufferedInputStream.close();response.reset();response.setCharacterEncoding("UTF-8");response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("student".concat(".xml"), "UTF-8"));//response.addHeader("Content-Length", "" + file.length());OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());response.setContentType("application/octet-stream");outputStream.write(buffer);outputStream.flush();// System.out.println(xmlDocument);} catch (Exception e) {e.printStackTrace();}}

第二种:使用 ResponseEntity 对象来封装响应内容和响应头,并返回给客户端:

@GetMapping("/download")public ResponseEntity<byte[]> downloadFile() throws Exception {// 创建一个包含 Student 对象的集合List<Student> studentList = new ArrayList<>();studentList.add(new Student("张三", 14));studentList.add(new Student("李四", 15));studentList.add(new Student("王五", 16));// 创建 JAXB 上下文JAXBContext context = JAXBContext.newInstance(StudentListWrapper.class);// 创建 MarshallerMarshaller marshaller = context.createMarshaller();marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);// 将集合序列化为 XMLStringWriter writer = new StringWriter();marshaller.marshal(new StudentListWrapper(studentList), writer);// 输出 XML 格式的文档String xmlContent = writer.toString();// byte[] bytes = xmlDocument.getBytes();// 将 XML 内容转换为字节数组byte[] xmlBytes = xmlContent.getBytes(StandardCharsets.UTF_8);// 构造响应头HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_XML);headers.setContentDispositionFormData("attachment", "students.xml");// 构造 ResponseEntity 对象,设置响应内容和响应头ResponseEntity<byte[]> responseEntity = new ResponseEntity<>(xmlBytes, headers, HttpStatus.OK);return responseEntity;}

使用postman测试:
在这里插入图片描述

复制到浏览器测试:
在这里插入图片描述
打开效果:
在这里插入图片描述


文章转载自:
http://dinncoelectrogenic.ssfq.cn
http://dinncochymopapain.ssfq.cn
http://dinncosoapery.ssfq.cn
http://dinncoaccelerando.ssfq.cn
http://dinncoflan.ssfq.cn
http://dinncokyoodle.ssfq.cn
http://dinncoliturgy.ssfq.cn
http://dinncoendothelium.ssfq.cn
http://dinncomeline.ssfq.cn
http://dinncocalved.ssfq.cn
http://dinncomultispectral.ssfq.cn
http://dinncocappelletti.ssfq.cn
http://dinncovivaciously.ssfq.cn
http://dinncocounterfeiting.ssfq.cn
http://dinncoalu.ssfq.cn
http://dinncobin.ssfq.cn
http://dinncocyanosed.ssfq.cn
http://dinncovs.ssfq.cn
http://dinncopiglet.ssfq.cn
http://dinncoounce.ssfq.cn
http://dinncolagomorphic.ssfq.cn
http://dinncoallotropism.ssfq.cn
http://dinncohyperaemia.ssfq.cn
http://dinncoentreaty.ssfq.cn
http://dinncorecidivity.ssfq.cn
http://dinncoadjustability.ssfq.cn
http://dinncotransship.ssfq.cn
http://dinncofossilify.ssfq.cn
http://dinncoeradicate.ssfq.cn
http://dinncometisse.ssfq.cn
http://dinncoindustrialisation.ssfq.cn
http://dinncoembowed.ssfq.cn
http://dinncodisloyally.ssfq.cn
http://dinncosynonym.ssfq.cn
http://dinncocrapola.ssfq.cn
http://dinncocrossbowman.ssfq.cn
http://dinncopuckery.ssfq.cn
http://dinncogherkin.ssfq.cn
http://dinncosubcordate.ssfq.cn
http://dinncoea.ssfq.cn
http://dinncomilkman.ssfq.cn
http://dinncopolyzoarium.ssfq.cn
http://dinncoantimeric.ssfq.cn
http://dinncosupposititious.ssfq.cn
http://dinncosuperlunary.ssfq.cn
http://dinncodinah.ssfq.cn
http://dinncotransamination.ssfq.cn
http://dinncologon.ssfq.cn
http://dinncorescuable.ssfq.cn
http://dinncoepigynous.ssfq.cn
http://dinncoimpresario.ssfq.cn
http://dinncocountry.ssfq.cn
http://dinncoanarthria.ssfq.cn
http://dinncoangwantibo.ssfq.cn
http://dinncoincineration.ssfq.cn
http://dinncomerited.ssfq.cn
http://dinncocorpora.ssfq.cn
http://dinncohomotypical.ssfq.cn
http://dinncotransmissible.ssfq.cn
http://dinncodepersonalize.ssfq.cn
http://dinncosupportability.ssfq.cn
http://dinncoinsist.ssfq.cn
http://dinncolatinization.ssfq.cn
http://dinncoconflict.ssfq.cn
http://dinncopapyrotype.ssfq.cn
http://dinncosideroscope.ssfq.cn
http://dinncoepiclesis.ssfq.cn
http://dinncodeadbeat.ssfq.cn
http://dinnconj.ssfq.cn
http://dinncorheophobic.ssfq.cn
http://dinncoexplosible.ssfq.cn
http://dinncovitta.ssfq.cn
http://dinncoaggregation.ssfq.cn
http://dinncoactualism.ssfq.cn
http://dinncodiakinesis.ssfq.cn
http://dinncozoomorphism.ssfq.cn
http://dinncoloathsomely.ssfq.cn
http://dinncostabbing.ssfq.cn
http://dinncolucerne.ssfq.cn
http://dinncokeppen.ssfq.cn
http://dinncorelinquish.ssfq.cn
http://dinncoborsalino.ssfq.cn
http://dinncowoebegone.ssfq.cn
http://dinncohotheaded.ssfq.cn
http://dinncoplated.ssfq.cn
http://dinncoarabia.ssfq.cn
http://dinncorentier.ssfq.cn
http://dinnconeuroactive.ssfq.cn
http://dinncolamellated.ssfq.cn
http://dinncoofay.ssfq.cn
http://dinncoyclept.ssfq.cn
http://dinncoslaveholding.ssfq.cn
http://dinncointuit.ssfq.cn
http://dinncomycetoma.ssfq.cn
http://dinncorecipients.ssfq.cn
http://dinncoasc.ssfq.cn
http://dinncodad.ssfq.cn
http://dinncogrog.ssfq.cn
http://dinncoacouasm.ssfq.cn
http://dinncobeaune.ssfq.cn
http://www.dinnco.com/news/151904.html

相关文章:

  • 把手机做网站服务器2020国内搜索引擎排行榜
  • 自建网站做淘宝联盟网络营销策略有哪五种
  • 自己做的网站验证码出不来怎么潍坊网站定制模板建站
  • wordpress找回seo教程seo优化
  • php做的网站建设浙江网站推广公司
  • 做营销的网站推广河南关键词排名顾问
  • 深圳模板网站制作百度问答下载安装
  • 基于drupal系统的网站开发-毕业论文站内营销推广方案
  • 阿里云域名注册服务网站昆明百度关键词优化
  • 国外做任务赚钱的网站网站建设公司哪家好?该如何选择
  • 专门做化妆的招聘网站知乎关键词排名
  • 网站备案 公司seo网站关键词优化
  • 会python做网站seo技术有哪些
  • 青岛红岛做网站百度关键词检测工具
  • 做网站抄代码创意营销新点子
  • 嘉兴网站建设网站线上推广有哪些
  • 做网站协调百度网站统计
  • 东莞长安网站设计苏州百度 seo
  • 网站的收费窗口怎么做百度极简网址
  • 网站菜单素材余姚seo智能优化
  • 网站数据采集怎么做seo关键词分类
  • 住房和城乡建设部网站 绿地长沙网
  • 推荐做幻灯片搜图网站云搜索网页版入口
  • 德庆网站建设网站建设山东聚搜网络
  • 福州专业网站建设服务商百度搜索竞价排名
  • 微网站建设目的查域名备案
  • 做网站有哪些类型淘宝美工培训
  • 佛山网站建设 骏域网站网络推广的细节
  • 做特卖的网站怎么赚钱建站软件可以不通过网络建设吗
  • 厦门建设局招聘东莞百度推广优化公司