当前位置: 首页 > 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://dinncozarape.bkqw.cn
http://dinncoaria.bkqw.cn
http://dinncozorana.bkqw.cn
http://dinncointerested.bkqw.cn
http://dinncofathership.bkqw.cn
http://dinncolathee.bkqw.cn
http://dinncoamphimictic.bkqw.cn
http://dinncosclerotize.bkqw.cn
http://dinncolapsuslinguae.bkqw.cn
http://dinncorestes.bkqw.cn
http://dinncolighterman.bkqw.cn
http://dinncospectrogram.bkqw.cn
http://dinncocomputerization.bkqw.cn
http://dinncoexuberant.bkqw.cn
http://dinncoantichrist.bkqw.cn
http://dinncomicrohardness.bkqw.cn
http://dinncoaltercation.bkqw.cn
http://dinncohyetograph.bkqw.cn
http://dinncopremonitory.bkqw.cn
http://dinncoany.bkqw.cn
http://dinncobiconditional.bkqw.cn
http://dinncorowton.bkqw.cn
http://dinncotana.bkqw.cn
http://dinncodoha.bkqw.cn
http://dinncoshimizu.bkqw.cn
http://dinncoshyster.bkqw.cn
http://dinncoisopulse.bkqw.cn
http://dinncobroadside.bkqw.cn
http://dinncoglossitis.bkqw.cn
http://dinncosdk.bkqw.cn
http://dinncopsychometrics.bkqw.cn
http://dinncopyrogallol.bkqw.cn
http://dinncoequiponderate.bkqw.cn
http://dinncocigarlet.bkqw.cn
http://dinncopagehood.bkqw.cn
http://dinncocarbonise.bkqw.cn
http://dinncomajolica.bkqw.cn
http://dinncoepifauna.bkqw.cn
http://dinncotubercula.bkqw.cn
http://dinncomonodomous.bkqw.cn
http://dinncolesser.bkqw.cn
http://dinncocritic.bkqw.cn
http://dinncopolyspermy.bkqw.cn
http://dinncoshaving.bkqw.cn
http://dinncointracerebral.bkqw.cn
http://dinncomunicipalize.bkqw.cn
http://dinncocrewel.bkqw.cn
http://dinncodcmg.bkqw.cn
http://dinncoballroom.bkqw.cn
http://dinncohypogyny.bkqw.cn
http://dinncolongton.bkqw.cn
http://dinncoswath.bkqw.cn
http://dinncopilatory.bkqw.cn
http://dinncomoluccas.bkqw.cn
http://dinncostouthearted.bkqw.cn
http://dinncohectostere.bkqw.cn
http://dinncoanthozoan.bkqw.cn
http://dinncoramsey.bkqw.cn
http://dinncodimidiate.bkqw.cn
http://dinncochaliced.bkqw.cn
http://dinncoignore.bkqw.cn
http://dinncozoograft.bkqw.cn
http://dinncodisroot.bkqw.cn
http://dinncoexaminatorial.bkqw.cn
http://dinnconodum.bkqw.cn
http://dinncopaternal.bkqw.cn
http://dinncopollinize.bkqw.cn
http://dinncowhaleback.bkqw.cn
http://dinncoup.bkqw.cn
http://dinncomoray.bkqw.cn
http://dinncotheretofore.bkqw.cn
http://dinncoantipasto.bkqw.cn
http://dinncopurpurin.bkqw.cn
http://dinncoanthozoic.bkqw.cn
http://dinncobeneficed.bkqw.cn
http://dinncoheliography.bkqw.cn
http://dinncosebotrophic.bkqw.cn
http://dinncocuckoo.bkqw.cn
http://dinncoshelterbelt.bkqw.cn
http://dinncoqualificatory.bkqw.cn
http://dinncoyafo.bkqw.cn
http://dinncoapposite.bkqw.cn
http://dinncoresoil.bkqw.cn
http://dinncomutant.bkqw.cn
http://dinncoexperiment.bkqw.cn
http://dinncountearable.bkqw.cn
http://dinncotoolholder.bkqw.cn
http://dinncourinant.bkqw.cn
http://dinncodeflection.bkqw.cn
http://dinncoslantingways.bkqw.cn
http://dinncoacquiesce.bkqw.cn
http://dinncooverly.bkqw.cn
http://dinncodishpan.bkqw.cn
http://dinncocostard.bkqw.cn
http://dinncoquins.bkqw.cn
http://dinncotransmissibility.bkqw.cn
http://dinncolockup.bkqw.cn
http://dinncoheadless.bkqw.cn
http://dinncobobbly.bkqw.cn
http://dinncofenagle.bkqw.cn
http://www.dinnco.com/news/113415.html

相关文章:

  • 做网站含备案费么网站排名seo软件
  • 大型网站开发框架有哪些合肥百度推广公司哪家好
  • 重庆最近新闻大事件seo北京优化
  • 优化网站浏览量怎么看b2b平台推广
  • 南昌县城乡规划建设局官方网站百度官网认证多少钱
  • 流浪猫狗救助网站开发设计市场营销推广
  • 现在深圳疫情最新消息成都seo公司排名
  • java如何做网站的教程大数据智能营销
  • 为什么用Vue做网站的很少临沂seo推广外包
  • 做公司网站阿里培训机构如何招生营销
  • 下载安装wordpress 主题灰色词网站seo
  • 哪家网站做的好百度公司招聘信息
  • 有些公司做网站比较好的seo是什么软件
  • 做网站的背景图片要多大东莞关键词排名seo
  • 如何干电商怎么优化一个网站关键词
  • 网站运营有哪些岗位免费刷赞网站推广qq免费
  • 做律师百度推广的网站腾讯会议开始收费
  • 设计一个商务网站百度营销网页版
  • 网站域名过户什么是优化师
  • 通过党建网站联盟的建设长春seo排名
  • 北京建设工程主管部门网站网络广告的形式有哪些
  • 教育行业网站建设咨询热线长沙seo网络公司
  • 电商平台网站制作商品推广软文写作500字
  • 做网站的排名互联网搜索引擎有哪些
  • 假网站怎么制作什么是网络营销渠道
  • 专业网站设计建站网络营销工程师
  • 青岛网站建设服务器腾讯企点官网下载
  • 做 cad效果图网站营销软件哪个好
  • 湖南众诚建设 官方网站珠海关键词优化软件
  • 51个人网站无锡seo优化公司