【发布时间】:2020-06-05 15:45:48
【问题描述】:
我正在努力寻找减少代码重复的方法。像这段代码一样,我的班级中有多个 Map 元素。如果你有什么,请给我建议..!
public Class MyObject{
private Map map1;
private Map map2;
private Map map3;
//having setter/getter
}
importDatabase(){
//here i have data in the map1, map2, map3 elements
importMap(MyObject.getMap1());
importMap(MyObject.getMap2());
importMap(MyObject.getMap3());
}
importMap(Map map){
//want to insert map objects into database at one go, instead of creating 3 methods for each type
Iterator iterator = map.values().iterator;
while(iterator.hasNext(){
}
}
【问题讨论】:
-
我建议您查看发布问题的 SO 指南。
-
@Pramod 是的,我会的。
标签: java jpa collections persist