我正在添加到在Eclipse中完成的项目中,该项目显示从各种数据库提取到网页的数据。我想弄清楚如何使用hashmap。我有一个名为“description”的变量/列,它将显示基于它之前列的值的描述。这些描述在我的hashmap中。我只是不知道如何拉取“描述”的价值。从Eclipse中的hashmap获取值
这里是DtoBuilder的一部分 -
private HashMap<String,String> itemDescrMap = null;
public VersionsDto build(Versions oneVersion){
VersionsDto result = null;
if(itemDescrMap==null){
itemDescrMap = loadItemDescrMap();
}
// Create instance of versions object and build it.
if(oneVersion != null){
result = new VersionsDto();
result.setStore(oneVersion.getStore());
result.setUpdatePackage(oneVersion.getUpdatePackage());
result.setDescription(oneVersion.getDescription());
这里就是HashMap中的一部分 -
private static HashMap<String,String> loadItemDescrMap(){
HashMap<String,String> map = new HashMap<String,String>();
map.put("CDSA", "Color Match");
map.put("CDSB", "New Formula Book");
map.put("CDSC", "Base Assignments");
map.put("CDSD", "Product Formulation");
map.put("CDSE", "Old TAC");
map.put("CDSF", "Colorant Systems");
map.put("CDSG", "Miscellaneous");
map.put("CDSH", "AFCD");
起初,我只是抓住了相同的数据,“描述”,因为我是为“updatePackage”,只是为了测试它将填充所有字段并将其显示到网页。所以现在我需要知道如何设置基于哈希映射的“description”值,其中第一个值(CDSD,CDSE等)是“updatePackage”列中所有可能的值,第二个值是相应的“描述“,我需要。
'itemDescrMap.get(oneVersion.getDescription())'? – Aaron
如何在相应的'result.setUpdatePackage(oneVersion.getUpdatePackage());'之前使用它? – BigRedEO
这将不会检索您需要的正确值。参考@ user6106573提供的答案 – dan