【发布时间】:2023-03-25 11:04:01
【问题描述】:
我有一个包含一些 for 循环的程序。该程序的想法是使用多个帐户登录一个网站并检索一个列表(每次登录都会带来一个不同的列表)。所以我设置它的方式是使用增强的 for 循环:
loginsList.put( "firstUsername", "firstPassword" );
loginsList.put( "secondUsername", "secondPassword" );
loginsList.put( "thirdUsername", "thirdPassword" );
loginsList.put( "fourthUsername", "fourthPassword" );
loginsList.put( "fifthUsername", "fifthPassword" );
for ( Entry<String, String> nextLogin : logins.entrySet() ) {
String nextUser = nextLogin.getKey();
String nextPass = nextLogin.getValue();
Response authenticateUserResponse = Jsoup.connect( WEBSITE_I_NEED_TO_LOGIN_TO )
.data( "username", nextUser )
.data( "password", nextPass )
.execute();
基本上这就是我想要的流程:
read()--> 获取列表----> 将列表发送到 write() 方法以将其写入数据库--> 循环并获取下一个登录信息-->read()--> 获取list--> 将其发送到 write()..etc..
但是我遇到的问题是我的循环在读取方法中运行,并且在所有帐户中遍历所有列表之前不会转到写入方法。本质上,写入最后只被调用一次,所以我现在拥有的是这样的(这是有缺陷的设计):
read()--->获取列表-->下一个账户--->获取列表---下一个账户--->获取列表--->write()
在我只读取一个块之后,如何在 Spring 中组织块处理来写入?
【问题讨论】:
标签: java spring spring-batch