欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么在SpringBatch中對(duì)框架進(jìn)行處理

怎么在Spring Batch中對(duì)框架進(jìn)行處理?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供巴楚網(wǎng)站建設(shè)、巴楚做網(wǎng)站、巴楚網(wǎng)站設(shè)計(jì)、巴楚網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、巴楚企業(yè)網(wǎng)站模板建站服務(wù),10余年巴楚做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

目標(biāo)1:程序隨機(jī)生成字符串,經(jīng)過(guò)Spring Batch后,統(tǒng)一在字符串后加入“----PROCESSED”,并輸出

目標(biāo)2:程序讀取txt文件,經(jīng)過(guò)Spring Batch后,統(tǒng)一加入如上字段,并輸出

Spring Batch的流程

  • 讀取數(shù)據(jù)----itemReader

  • 處理數(shù)據(jù)----itemProcess

  • 數(shù)據(jù)寫入----itemWrite

分析目標(biāo)可知,兩個(gè)目標(biāo)的輸入數(shù)據(jù)源不同,處理方式基本一致,數(shù)據(jù)完成后的寫入規(guī)則一致

由此可以分段完成代碼

itemReader

目標(biāo)一

這里沒(méi)有使用Spring Batch自帶的集中reader,所以自定義了隨機(jī)生成字符串的reader

這里代碼并不完善,reader會(huì)無(wú)線循環(huán)生成隨機(jī)字符串,但不影響本次學(xué)習(xí)的目的

public class MyItemReader implements ItemReader<String> {
  @Override
  public String read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    return RandomStringUtils.randomAlphabetic(10);
  }
}

目標(biāo)二

由于是讀取文件中的內(nèi)容,所以不用自定義reader實(shí)現(xiàn),可直接使用FlatFileItemReader,在Batch的config中配置即可

  @Bean
  public ItemReader<String> textReader(){
 
    FlatFileItemReader<String> reader=new FlatFileItemReader<>();
    File file = new File("D:\\FTP\\ttest.txt");
    reader.setResource(new FileSystemResource(file));
    reader.setLineMapper(new LineMapper<String>() {
      @Override
      public String mapLine(String line, int lineNumber) throws Exception {
        return line;
      }
    });
    return reader;
 
  }

itemProcess

這里采用同一種處理方式即可

public class MyItemProcessor implements ItemProcessor<String,String> {
 
  @Override
  public String process(String s) throws Exception {
    return s+"---------PROCESSED";
  }
}

itemWriter

也采用同一種即可

public class MyItemWriter implements ItemWriter<String> {
  @Override
  public void write(List<? extends String> items) throws Exception {
    for (String item : items) {
      System.out.println(item);
    }
  }
}

配置完成Batch Config

@Configuration
@EnableBatchProcessing
public class BatchConfiguration extends DefaultBatchConfigurer {
 
  @Autowired
  public StepBuilderFactory stepBuilderFactory;
  @Autowired
  public JobBuilderFactory jobBuilderFactory;
 
  @Bean
  public MyItemProcessor processor(){
    return new MyItemProcessor();
  }
 
  @Bean
  public ItemWriter<String> writer(){
    return new MyItemWriter();
  }
 
  @Bean
  public ItemReader<String> textReader(){
    FlatFileItemReader<String> reader=new FlatFileItemReader<>();
    File file = new File("D:\\FTP\\ttest.txt");
    reader.setResource(new FileSystemResource(file));
    reader.setLineMapper(new LineMapper<String>() {
      @Override
      public String mapLine(String line, int lineNumber) throws Exception {
        return line;
      }
    });
    return reader;
  }
 
  @Bean
  public ItemReader<String> stringReader(){
    return new MyItemReader();
  }
 
  @Override
  public void setDataSource(DataSource dataSource) {
    super.setDataSource(dataSource);
  }
 
  @Bean
  public Step myStep(){
    return stepBuilderFactory
        .get("step1")
        //這個(gè)chunk size是最后調(diào)用寫入的時(shí)候,一次性寫入多少條已處理的數(shù)據(jù)
        .<String,String>chunk(10)
//        .reader(textReader())
        .reader(stringReader())
        .processor(processor())
        .writer(writer())
        .build();
 
  }
 
  @Bean
  public Job MyJob(){
    return jobBuilderFactory
        .get("MyJOB")
        .listener(new JobExecutionListenerSupport(){
          //所有處理結(jié)束后調(diào)用
          @Override
          public void afterJob(JobExecution jobExecution) {
            if(jobExecution.getStatus() == BatchStatus.COMPLETED){
              System.out.println("OK");
            }
          }
        })
        .flow(myStep())
        .end()
        .build();
  }
}

關(guān)于怎么在Spring Batch中對(duì)框架進(jìn)行處理問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

文章標(biāo)題:怎么在SpringBatch中對(duì)框架進(jìn)行處理
當(dāng)前網(wǎng)址:http://aaarwkj.com/article34/gdijse.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、App開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
国产精品一区波多野结衣| 综合av在线一区天堂| 国产婷婷色三区一区二区| 高清高潮少妇一区二区三区| av二区不卡国产精品| 日韩成人在线视频中文字幕| 亚洲欧美日韩国产在线一区| 五月婷婷丁香六月在线综合| 国产丝袜肉丝在线播放| 天天操天天射夜夜撸| 日韩一区精品视频一区二区| 中文字幕亚洲天堂久久| 婷婷色中文字幕综合在线| 成人性生活三级黄色片| 亚洲伦理国产一国产二| 亚洲国产精品成人女人| 精品少妇一区二区三区| 在线观看亚洲毛片网站| 伊人狼人综合视频在线播放| 日韩a国产v亚洲欧美精品| 欧美日韩激情在线一区| 日本在线中文字幕乱码| 日本经典三级在线视频| 欧美经典三级一区二区三区| 久国产精品韩国三级视频| 欧美日韩免费高清视视频| 亚洲欧美日韩一区91| 日韩国产一区二区三区精品| 欧美日韩亚洲国产精品视频| 久久久久久亚洲精品人妻| 国内揄拍国内精品对久久| 国产成人久久久精品一区| 国产精品一区在线免费看| 国产成人自拍激情视频| 日本在线观看精品综合| 国产在线91精品入口| 熟女俱乐部五十路六十路 | 国内精品人妻中文字幕| 国产精品欧美久久久久无| 亚洲激情在线观看一区| 国产精品一二三在线看|