Hibernate 如何迭代映射<;字符串,列表>;map=新HashMap<;字符串,列表>;()在使用JSTL的jsp页面中
我将两个列表添加到一个Map Map=newhashmap()。我希望使用JSTL在jsp页面中从中获取值 我的发明者是Hibernate 如何迭代映射<;字符串,列表>;map=新HashMap<;字符串,列表>;()在使用JSTL的jsp页面中,hibernate,jsp,spring-mvc,hashmap,jstl,Hibernate,Jsp,Spring Mvc,Hashmap,Jstl,我将两个列表添加到一个Map Map=newhashmap()。我希望使用JSTL在jsp页面中从中获取值 我的发明者是 @RequestMapping("/addprogram") public ModelAndView thematicday() { Map<String, List> map = new HashMap<String, List>(); try{ List<Themes> theme
@RequestMapping("/addprogram")
public ModelAndView thematicday()
{
Map<String, List> map = new HashMap<String, List>();
try{
List<Themes> theme=dataServices.getTheme();
List<String> themeday=dataServices.getThematicDate();
map.put("theme", theme);
map.put("themeday", themeday);
}
catch(Exception e)
{
e.printStackTrace();
}
return new ModelAndView("thematicday","map",map);
}
请试试这个
<c:forEach var="themedays" items="${map.themeday}">
<c:foreach var="theme" items="${themedays}">
<b> ${theme} </b>
</c:foreach>
</c:foreach>
${theme}
下面的方法可用于使用字符串和bean对象列表迭代hashmap
<c:forEach items="${map}" var="events">
// iterate the key here
StringValues= ${events.key}
// iterate the values of list here
<c:forEach items="${events.value}" var="item" >
${item}
</c:forEach>
</c:forEach>
//在这里迭代键
StringValues=${events.key}
//在此处迭代列表的值
${item}
请参见此处:
Object.toString()
,你得到的是什么对象,你调试过了吗,你看到你的列表了吗。你正在添加Object.toString()
进入您的列表
,问题就在这里,请更正此问题。您可能需要调用getter on result或类似的result.get(“主题”)
,然后添加到列表
,但我不能使用List result=(List)query.List();而不是List result=(List)query.List();。当我使用此列表result=(List)时query.list();for(ThematicDay p:result){System.out.println(“*********************”+p.getThemedate());}它显示错误“java.lang.ClassCastException:[Ljava.lang.Object;无法转换为com.astra.model.ThematicDay”;它还打印列表的值,这里是[Ljava.lang.Object;@1a99a72[Ljava.lang.Object;@1dadad3.实际上我需要得到2015年1月14日第100天2015年2月14日的结果DAY107@Priyanka似乎您没有正确访问bean属性,您能用您现在正在尝试的代码更新您的问题吗?但是我不能使用List result=(List)query.List()而不是List result=(List)query.List()。请您解释一下如何在我的DaoImpl中存储列表中的值。您需要观察所获得的列表
,在填充列表
时使用一个数据,不要使用对象。toString()
,迭代列表
,获取主题的值
,并填充列表
<c:forEach var="Date" items="${map}">
<c:if test="${Date.key == 'themeday'}">
<div class="bottom-article">
<ul class="meta-post">
<li><a href="#" class="tl_1"> ${Date.value[0]} </a></li>
<li><a href="#" class="tl_2">${Date.value[1]} </a></li>
</ul>
</div>
</c:if>
</c:forEach>
[Ljava.lang.Object;@762b0f
[Ljava.lang.Object;@4f983
<c:forEach var="themedays" items="${map.themeday}">
<c:foreach var="theme" items="${themedays}">
<b> ${theme} </b>
</c:foreach>
</c:foreach>
<c:forEach items="${map}" var="events">
// iterate the key here
StringValues= ${events.key}
// iterate the values of list here
<c:forEach items="${events.value}" var="item" >
${item}
</c:forEach>
</c:forEach>