Java 访问传递给SpringJSP页面的映射中的特定键

Java 访问传递给SpringJSP页面的映射中的特定键,java,spring,jsp,map,Java,Spring,Jsp,Map,我将树形图传递给JSP页面。地图包含当前或下个月的日期作为关键字。传递的数据必须在JSP页面中呈现。因此,我需要一种从映射中访问.containsKey()或.containsValue()或.get()方法的方法。我尝试了这些方法,但总有例外 当我使用.get(1)或.get(“1”)方法时,eclipse向我显示了一个ClassCastException java.lang.Integer cannot be cast to java.lang.Long 有什么办法解决我的问题吗 编辑:代

我将树形图传递给JSP页面。地图包含当前或下个月的日期作为关键字。传递的数据必须在JSP页面中呈现。因此,我需要一种从映射中访问
.containsKey()
.containsValue()
.get()
方法的方法。我尝试了这些方法,但总有例外

当我使用
.get(1)
.get(“1”)
方法时,eclipse向我显示了一个
ClassCastException

java.lang.Integer cannot be cast to java.lang.Long
有什么办法解决我的问题吗

编辑:代码:

public TreeMap<String, String> getCalendarEntries(
    boolean showNextMonth) throws Exception{
TreeMap<String, String> treeMap = new TreeMap<String, String>();

// doing some stuff... 

treeMap.put("2", "someValue"); 

// ..

return treeMap;
}
public树映射getCalendarEntries(
布尔值showNextMonth)引发异常{
TreeMap TreeMap=新的TreeMap();
//做一些事情。。。
树映射put(“2”,“someValue”);
// ..
返回树图;
}
控制器

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String home(Locale locale, Model model) throws Exception {
// do stuff.. 

TreeMap<String, String> treeMap = getCalendarEntries(true);

model.addAttribute("treeMap", treeMap);
return "home"
}
@RequestMapping(value=“/test”,method=RequestMethod.GET)
公共字符串home(区域设置、模型)引发异常{
//做事。。
TreeMap TreeMap=getCalendarEntries(true);
addAttribute(“treeMap”,treeMap);
返回“家”
}
JSP页面

<c:forEach var="calendarEntry" items="${calendarEntries }">
${calendarEntry.getKey()}-${calendarEntry.getValue()}
// Returns the key/value mapping
</c:forEach>

${calendarEntries.get("2")}
// returns nothing. 

${calendarEntry.getKey()}-${calendarEntry.getValue()}
//返回键/值映射
${calendarEntries.get(“2”)}
//不返回任何内容。

问题在于您的地图结构是这样的

    Map<Long,Object> map =new HashMap<Long,Object>()
    map.put(1l,"value1");
    map.put(2l,"value2");
Map Map=newhashmap()
地图放置(1l,“值1”);
地图放置(2l,“值2”);
但是您正在使用
.get(1)
访问它。这里
1
是一个整数,系统试图转换为long,但失败了


尝试
.get(1l)
而不是
.get(1)

,这就是我感到困惑的原因。这张地图很漂亮。我没有在项目的任何地方使用long。我将它切换到并通过.get(“2”)在JSP文件中访问它。但它没有返回任何值。但是,当我在映射上使用for循环进行迭代时,我会得到JSP页面中的所有值。@smsn请检查如何通过“现在工作正常”的方法将数据填充到MapWell。问题是我试图访问“2”,而不是“02”。对于整数1,我通过Integer.parseInt()方法填充映射。@smsnheck-hmm。。伟大的发现。。。。