如何在spring视图中迭代链表的地图

时间:2013-12-27 17:20:38

标签: java jsp spring-mvc

我已编写以下代码将模型返回到spring view(jsp)。但我无法在模型上旋转。

任何身体都可以帮助我。

以下是示例:

@RequestMapping(value = "/news", method = RequestMethod.GET)
    public ModelAndView getNewsView() {
        ModelAndView modelNView = new ModelAndView();
        modelNView.setViewName("/content/news");
        Criterion activeCrit = Restrictions.eq("active", true);
        Criterion typeCrit = Restrictions.eq("type", tsService.findByCode(ContentType.class, "NEWS_TYPE"));
        List<Content> matches = (List<Content>)tsService.findMatches(Content.class, Order.desc("createDateTime"), 3, activeCrit, typeCrit);

        LinkedList<HashMap<String, String>> mapList = new LinkedList<HashMap<String,String>>();
        for(Content matcher : matches){
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("id", matcher.getId().toString());
            map.put("name", matcher.getName());
            map.put("description", matcher.getDescription());
            mapList.add(map);
        }
        modelNView.addObject("model", mapList);
        return modelNView;
    }

当我调用这个模型时,jsp显示了意志。我使用了以下代码。

${model}

但如果我在列表中有以下数据

,再次无法如何打印

1 naveen'这只是一个例子'

2 parveen'desc'

1 个答案:

答案 0 :(得分:0)

你可以在你的jsp中创建一个forEach循环,它循环遍历'model'中的每个'map'。

例如,

<c:forEach items="${model}" var="map">
     <div>
         ${map.name} <br/>
         ${map.description}
     <div/>
</c:forEach>