我有两个相同的模型类,但它们在不同的包中。 第一个是:model.my.prod.Model
和第二model.my.test.Model
2个相同的类,但来自不同的包的通用使用
我也为这个model.my.prod.Model
内搭一件Model
类作为参数的简单映射:
public class Mapper{
private static Map<Model, String> models= new HashMap<>();
static {
models.put(Model.IMAGE_JPG, MediaType.IMAGE_JPEG_VALUE);
models.put(Model.IMAGE_GIF, MediaType.IMAGE_GIF_VALUE);
}
public static String createModelMap(Model model) {
if (models.containsKey(model)) {
return models.get(model);
} else {
throw new ModelException("Exeception");
}
}
}
现在我想用这个Mapper
也为model.my.test.Model
,是否有可能没有此Mapper
的副本并更改Model
包?
这是一个解决方案,但我认为它与连接重复的'createModelMap'函数代码。 – allocer