映射器接口将请求映射到JobParameters

问题描述

我有一个可以运行作业的组件:

当前构建的job参数是固定的,但是不同的feed应该提供他们自己的将请求映射到JobParameters的方式,因此我想出了一个通用的Mapper接口和一个{{ 1}}接口,应将RequestMapper映射到MyRequest

JobParameters

问题是我有@Component public class MyJobRunner { private JobLauncher jobLauncher; private JobExplorer jobExplorer; private JobLocator jobLocator; private RequestMapper requestMapper; @Autowired public MyJobRunner(JobLocator jobLocator,JobExplorer jobExplorer,JobLauncher jobLauncher,RequestMapper requestMapper) { this.jobLocator = jobLocator; this.jobExplorer = jobExplorer; this.jobLauncher = jobLauncher; this.requestMapper = requestMapper; } public MyResponse run(final MyRequest request,final String id) { JobParameters parameters = getJobParameters(request,id); } private JobParameters getJobParameters(MyRequest request,String id) { //current JobParametersBuilder parameters = new JobParametersBuilder(); parameters.addString("name",request.getValue(NAME)); parameters.addString("date",request.getValue(DATE)); parameters.addString(ID.getKeyName(),id); return parameters.toJobParameters(); //target is replace the above with requestMapper.map(...) to transform request to JobParameters through the interface } } public interface Mapper<F,T> { T map(F from); } public interface RequestMapper extends Mapper { } 字段,该字段也应在JobParameters中,但不在id对象中。在那种情况下,我应该如何设计MyRequest接口,然后设计RequestMapper?我不确定是否可以将HashMap用作通用类型:

RequestMapper

其中键是id,值是请求对象。但是也许有一种更清洁的方法可以实现这一目标。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)