如何在Java8中反射mybatis映射器将不同的实体持久化到一个位置

如何在Java8中反射mybatis映射器将不同的实体持久化到一个位置,java,java-8,mybatis,Java,Java 8,Mybatis,现在,我想使用Java 8中的Mybatis将一些公共字段写入不同的表中,我不想使用reflect的内容如下: private void calcSingle(Entity appListRecord,AppListMapper mapper){ appListMapper.updateByPrimaryKeySelective(envelopeAppList); } private void calcSingle(T appListRecord

现在,我想使用Java 8中的Mybatis将一些公共字段写入不同的表中,我不想使用reflect的内容如下:

private void calcSingle(Entity appListRecord,AppListMapper mapper){
                appListMapper.updateByPrimaryKeySelective(envelopeAppList);
    }
    private void calcSingle(T appListRecord,E mapper){

   // pass different entity and using reflection to invoke the methond updateByPrimaryKeySelective method(each mapper invoke the same method)
        }
Method method = mapper.getClass().getMethod("updateByPrimaryKeySelective", envelopeAppList.getClass());
method.invoke(mapper, envelopeAppList);
但是我已经写了很多类似这样的复杂代码,现在我想写一次这样的代码:

private void calcSingle(Entity appListRecord,AppListMapper mapper){
                appListMapper.updateByPrimaryKeySelective(envelopeAppList);
    }
    private void calcSingle(T appListRecord,E mapper){

   // pass different entity and using reflection to invoke the methond updateByPrimaryKeySelective method(each mapper invoke the same method)
        }
Method method = mapper.getClass().getMethod("updateByPrimaryKeySelective", envelopeAppList.getClass());
method.invoke(mapper, envelopeAppList);
然后我可以使用一个函数并传递不同的Entry和mapper以避免复制代码。我应该做些什么来存档此文件?有什么建议吗?

请这样做:

private void calcSingle(Entity appListRecord,AppListMapper mapper){
                appListMapper.updateByPrimaryKeySelective(envelopeAppList);
    }
    private void calcSingle(T appListRecord,E mapper){

   // pass different entity and using reflection to invoke the methond updateByPrimaryKeySelective method(each mapper invoke the same method)
        }
Method method = mapper.getClass().getMethod("updateByPrimaryKeySelective", envelopeAppList.getClass());
method.invoke(mapper, envelopeAppList);

目前尚不清楚MyBatis是如何涉及的,但可能通用方法签名需要类似于:
void calcSingle(T record,Mapper Mapper)