org.springframework.batch.item.xml.StaxEventItemWriter Java Examples
The following examples show how to use
org.springframework.batch.item.xml.StaxEventItemWriter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlFileItemWriterDemo.java From SpringAll with MIT License | 6 votes |
private StaxEventItemWriter<TestData> xmlFileItemWriter() throws IOException { StaxEventItemWriter<TestData> writer = new StaxEventItemWriter<>(); // 通过XStreamMarshaller将TestData转换为xml XStreamMarshaller marshaller = new XStreamMarshaller(); Map<String,Class<TestData>> map = new HashMap<>(1); map.put("test", TestData.class); marshaller.setAliases(map); // 设置xml标签 writer.setRootTagName("tests"); // 设置根标签 writer.setMarshaller(marshaller); FileSystemResource file = new FileSystemResource("/Users/mrbird/Desktop/file.xml"); Path path = Paths.get(file.getPath()); if (!Files.exists(path)) { Files.createFile(path); } writer.setResource(file); // 设置目标文件路径 return writer; }
Example #2
Source File: ItemWriterConfigure.java From SpringAll with MIT License | 6 votes |
@Bean public StaxEventItemWriter<TestData> xmlFileItemWriter() throws Exception { StaxEventItemWriter<TestData> writer = new StaxEventItemWriter<>(); // 通过XStreamMarshaller将TestData转换为xml XStreamMarshaller marshaller = new XStreamMarshaller(); Map<String, Class<TestData>> map = new HashMap<>(1); map.put("test", TestData.class); marshaller.setAliases(map); // 设置xml标签 writer.setRootTagName("tests"); // 设置根标签 writer.setMarshaller(marshaller); FileSystemResource file = new FileSystemResource("/Users/mrbird/Desktop/file.xml"); Path path = Paths.get(file.getPath()); if (!Files.exists(path)) { Files.createFile(path); } writer.setResource(file); // 设置目标文件路径 return writer; }
Example #3
Source File: BatchConfig.java From Spring-5.0-Cookbook with MIT License | 6 votes |
@Bean("writer2") public ItemWriter<Permanent> xmlWriter() { StaxEventItemWriter<Permanent> xmlFileWriter = new StaxEventItemWriter<>(); String exportFilePath = "./src/main/resources/emps.xml"; xmlFileWriter.setResource(new FileSystemResource(exportFilePath)); xmlFileWriter.setRootTagName("employees"); Jaxb2Marshaller empMarshaller = new Jaxb2Marshaller(); empMarshaller.setClassesToBeBound(Permanent.class); xmlFileWriter.setMarshaller(empMarshaller); System.out.println("marshalling");; return xmlFileWriter; }