有没有办法在executecontext中添加除read(),updated()和open()方法之外的条目。
就像下面的代码一样,我试图在close方法中添加条目。
public class MyFileReader extends FlatFileItemReader<AccountDetails>{
private long currentRowProcessedCount = 0;
@Autowired
private ExecutionContext executionContext;
@Override
public synchronized AccountDetails read() throws Exception, UnexpectedInputException, ParseException {
AccountDetails accDetailsObj = super.read();
currentRowProcessedCount++;
return accDetailsObj;
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
currentRowProcessedCount = executionContext.getLong(Constants.CONTEXT_COUNT_KEY.getStrValue(),0);
this.executionContext = executionContext;
}
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
executionContext.putLong(Constants.CONTEXT_COUNT_KEY.getStrValue(), currentRowProcessedCount);
}
@Override
public void close() throws ItemStreamException {
System.out.println("close --------------"+currentRowProcessedCount);
System.out.println(executionContext.getLong(Constants.CONTEXT_COUNT_KEY.getStrValue()));
this.executionContext.putLong(Constants.CONTEXT_COUNT_KEY.getStrValue(), currentRowProcessedCount);
}
}
在上面的示例中,我无法更新新条目。 它只是作为readonly工作。我可以读数据但不能写。
class abc{
@Autowired
private ExecutionContext executionContext;
public AccountDetails mapFieldSet(FieldSet fieldSet) throws BindException {
executionContext.putLong(Constants.CONTEXT_COUNT_KEY.getStrValue(), 47);
return accDetailsObj;
}
}
我还需要在其他类中更新executionContext。 有什么办法吗?
答案 0 :(得分:0)
您只需使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<div id="navi"> NAVIGATION <i class="fa fa-chevron-down"></i></div>
<!--Navigation-->
<div id="navigation">
<div id="navigationin"><center>
<a href="{text:Link One Url}"><i class="fa fa-user-circle"></i><span>my stuff</span></a>
<a href="{text:Link Two Url}"><i class="fa fa-question-circle"></i><span>tutorials</span></a>
<a href="{text:Link Nine Url}"><i class="fa fa-folder-open-o"></i><span>archive</span></a>
<a href="{text:Link Three Url}"><i class="fa fa-star"></i><span>actors</span></a>
<a href="{text:Link Four Url}"><i class="fa fa-film"></i><span>tv shows</span></a>
<a href="{text:Link Eight Url}"><i class="fa fa-link"></i><span>links</span></a>
<a href="{text:Link Five Url}"><i class="fa fa-file-video-o"></i><span>gifsets</span></a>
<a href="{text:Link Six Url}"><i class="fa fa-file-image-o"></i><span>photosets</span></a>
<a href="{text:Link Seven Url}"><i class="fa fa-square-o"></i><span>icons</span></a>
<a href="{text:Twitter url}" target="_blank"><i class="fa fa-twitter-square"></i><span>twitter</span></a>
<a href="{text:Instagram url} target="_blank""><i class="fa fa-instagram"></i><span>instagram</span></a>
<a href="{text:Youtube url}" target="_blank"><i class="fa fa-youtube"></i><span>youtube</span></a>
</center>
</div>
</div>
覆盖已有的值。
ExecutionContext由put(String key, Object value)
支持,所以如果你真的想要它,你可以通过反射引用它,然后使用ConcurrentHashMap
等......
还计算已在computeIfAbsent
中实现,如果你继承了它(你是),这应该已经解决了。