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

打开网站出现directory甘肃交通建设监理公司网站

打开网站出现directory,甘肃交通建设监理公司网站,怎么做网站变更,肇庆企业网站关键词优化教程作为Spring Batch的坚定倡导者#xff0c;我一直在谈论Spring Batch的概念#xff0c;它为开发人员提供了一个框架#xff0c;使他们可以专注于解决业务需求。 这样#xff0c;它使开发人员不必花费过多的时间来解决所有技术问题以支持该解决方案。 为了说明我的意思… 作为Spring Batch的坚定倡导者我一直在谈论Spring Batch的概念它为开发人员提供了一个框架使他们可以专注于解决业务需求。 这样它使开发人员不必花费过多的时间来解决所有技术问题以支持该解决方案。 为了说明我的意思我们将采用我之前编写的Spring Batch示例之一并针对需要的其他业务需求进行一些增强。 新问题 在我的Spring Batch系列的第三部分中我们介绍了一个处理大型Excel文件输出的教程。 后来确定另一个业务部门需要相同的数据但是他们需要以管道分隔的文本文件格式只有三个字段输出数据。 有两种不同的方法可以执行此操作但是在本示例中我将向您展示如何快速实现自己的ItemStreamReader 该项目将写作委派给各个作家。 我们需要做的第一件事是创建ItemStreamReader的外壳。 我称之为MultiFormatItemWriter 。 这是外壳的样子 package com.keyhole.example;import java.io.IOException; import java.util.List;import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.annotation.AfterStep; import org.springframework.batch.core.annotation.BeforeStep; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemStreamWriter; import org.springframework.batch.item.file.FlatFileItemWriter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component;import com.keyhole.example.poi.StockData;Component(multFormatItemWriter) Scope(step) public class MultiFormatItemWriter implements ItemStreamWriterStockData {Overridepublic void write(List? extends StockData items) throws Exception {}BeforeSteppublic void beforeStep(StepExecution stepExecution) {}AfterSteppublic void afterStep(StepExecution stepExecution) throws IOException {}Overridepublic void open(ExecutionContext executionContext) throws ItemStreamException {}Overridepublic void update(ExecutionContext executionContext) throws ItemStreamException {}Overridepublic void close() throws ItemStreamException {}} 接下来我们需要对上一个示例中的现有StockDataExcelWriter进行一些调整以使其在新的MultiFormatItemWriter作为委托工作。 我还发现前面的示例存在一些与来自Nasdaq的数据流有关的问题。 其中一个字段的格式已更改该示例不再起作用因此必须先解决该问题然后我们才能继续。 错误修复将StockData上marketCap的字段类型从BigDecimal更改为String。 这些值现在在数据Feed中显示为“ $ 14.5M”和类似的值。 错误修复由于数据格式已更改并且这些博客文章大多使用静态示例因此我在src / test / resources下的data.stock包中创建了一个名为companylist.csv的股票数据输入文件。 错误修复修改了库存数据读取器以使用此数据文件代替实时的Nasdaq提要。 从StockDataExcelWriter删除了Scope “步骤”注释。 这是必需的因为MultiFormatItemWriter作用域是步骤级别。 从StockDataExcelWriter删除了BeforeStep和AfterStep批注因为这些方法将直接从MultiFormatItemWriter中调用。 注释了将每个记录写入Excel文件300次的write方法内部的for循环。 这用于大型excel文件演示因此需要还原该示例才能再次使用。 现在我们已经解决了StockDataExcelWriter 我们需要解决业务所需的其他格式输出。 第二个输出应该在管道分隔的文本文件中并且仅包含符号名称和最后销售字段。 对于这个委托作者我们将使用FlatFileItemWriter 它是Spring Batch提供的许多输出组件之一。 要使用它这是一个非常简单的配置更改看起来像这样 bean namepipeDelimitedExtractFile classorg.springframework.batch.item.file.FlatFileItemWriterproperty nameresource valuefile:/data/example/excel/extract-example.txt /property namelineAggregatorbean classorg.springframework.batch.item.file.transform.DelimitedLineAggregatorproperty namedelimiter value| /property namefieldExtractorbean classorg.springframework.batch.item.file.transform.BeanWrapperFieldExtractorproperty namenames valuesymbol,name,lastSale //bean/property/bean/property /bean 由于Spring Batch具有扎根于Spring框架的基础因此可以轻松配置提供的FlatFileItemWriter并将Bean连接到应用程序代码中。 在这种情况下我们将使用提供的DelimitedLineAggregator创建FlatFileItemWriter 将管道字符指定为定界符并将fieldExtractor设置为使用BeanWrapperFieldExtractor 。 BeanWrapperFieldExtractor获取发送到ItemStreamWriter的StockData记录列表并提取由逗号分隔的StockData bean中的字段名称列表指定的字段。 最后指定用于输出的资源在这种情况下为文件extract-example.txt并将其写入/ data / example / excel目录。 现在我们要做的就是将两个委托编写器连接到我们的MultiFormatItemWriter 。 确保在适当的方法中调用了委托编写器然后完成 这是MultiFormatITemWriter的最终代码清单 package com.keyhole.example;import java.io.IOException; import java.util.List;import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.annotation.AfterStep; import org.springframework.batch.core.annotation.BeforeStep; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemStreamWriter; import org.springframework.batch.item.file.FlatFileItemWriter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component;import com.keyhole.example.poi.StockData; import com.keyhole.example.poi.StockDataExcelWriter;Component(multFormatItemWriter) Scope(step) public class MultiFormatItemWriter implements ItemStreamWriterStockData {Autowiredprivate StockDataExcelWriter stockDataExcelWriter;AutowiredQualifier(pipeDelimitedExtractFile)private FlatFileItemWriterStockData extractWriter;Overridepublic void write(List? extends StockData items) throws Exception {stockDataExcelWriter.write(items);extractWriter.write(items);}BeforeSteppublic void beforeStep(StepExecution stepExecution) {stockDataExcelWriter.beforeStep(stepExecution);}AfterSteppublic void afterStep(StepExecution stepExecution) throws IOException {stockDataExcelWriter.afterStep(stepExecution);}Overridepublic void open(ExecutionContext executionContext) throws ItemStreamException {extractWriter.open(executionContext);}Overridepublic void update(ExecutionContext executionContext) throws ItemStreamException {extractWriter.update(executionContext);}Overridepublic void close() throws ItemStreamException {extractWriter.close();}} 如您所见这里确实没有太多工作要做这就是我想指出的。 我并没有真正显示出使用某些内置的读取器和写入器可以简单地实现某些业务解决方案。 最后的想法 现在我确实提到了解决此问题的几种方法。 第二个将利用Spring Batch随附的CompositeItemWriter 。 它所做的几乎和我在这里所做的完全相同只是它获取了ItemWriters的列表并在实现的每个方法中循环遍历它们。 在那种情况下我将转换我的StockDataExcelWriter来实现ItemStreamReader接口并且将用CompositeItemWriter代替MultiFormatOutputWriter 它将在作业配置xml中进行配置。 更少的代码。 因此我今天在本文中的观点是表达如何使用Spring Batch提供的几个已经实现的组件轻松解决最常见的任务和业务解决方案。 这个示例和其他示例可以在GitHub的以下位置找到 https : //github.com/jonny-hackett/batch-example 。 翻译自: https://www.javacodegeeks.com/2016/08/spring-batch-multiple-format-output-writer.html
http://wiki.neutronadmin.com/news/109402/

相关文章:

  • 网站设计与开发公司最好的国际贸易网站
  • 修水县城乡建设局网站网络服务合同范本
  • 网站里的友情链接阿里巴巴国际站关键词推广
  • 站长之家域名查询鹿少女云南电信网站备案
  • vs2010做网站子域名大全
  • 网站统计模块周村网站建设
  • 网站建设上线合肥网站建设技术托管
  • 做微商怎么通过网站和贴吧引流客源滨海网站建设找哪家好
  • 360未经证实的网站如何做网站加载等待
  • 网站建设设计主要系统营销课程培训都有哪些
  • 做电商有那个网站东莞网站建设乐云seo在线制作
  • 曲周企业做网站推广如何开发自己的小程序
  • 网页设计素材站洛阳网站seo
  • seo技术优化整站wordpress 菜单 数据库
  • 如何让人帮忙做网站温州seo全网营销
  • 移动端网站搭建网站制作关键字排名
  • 网站备案与服务器东莞市有多少个镇
  • c# asp.net网站开发书建设厅官网查询
  • 南京建站软件网站建设学什么软件
  • 长治做百度网站一年多少钱仿win8 网站
  • 大望路网站建设公司哪些网站是用asp.net做的
  • 站群cms源码网站域名查询注册
  • 青岛网站设计模板建材在哪些网站做
  • 淄博网站网站建设东莞最大的网络公司
  • 龙华住房和建设局网站怎么无法登陆现货做网站
  • 普陀区网站建设公司钢筋网片规格型号
  • 网站天天做收录有效果吗wordpress 缓存用什么
  • 网站建设公司资质设计wordpress页面模板下载地址
  • 徐州网站开发如何在线教育
  • jsp网站开发如何把自横批排动漫设计属于什么大类