STL访问Map问题,key为Integer或Long

 

 

 

Map<Integer, String> map = new HashMap<Integer, String>();  
map.put(1, "One");  
map.put(2, "Two");  
<c:out value="${map[1]}"/>  

 

 

 

换成

Map<Long, String> map = new HashMap<Long, String>();  
map.put(1L, "One");  

 

 

 

原因是JSTL默认把数字封装成Long类型。

 

另一个问题:类型转换

 

 

Map<Long, String> map = new HashMap<Long, String>();

${map[obj.id]}

 

obj.id定义为int类型时,无法取到值。需要将obj.id转为Long。

 

 

转自 http://blog.csdn.net/moreorless/article/details/6545457

 

 

posted @ 2018-01-12 11:10  rubekid  阅读(1252)  评论(0编辑  收藏  举报