2014-02-09 34 views
0

使用控制器构建要传递给JSP的数据,设计它以允许在循环内循环的最佳方式是什么?在直接的JSP中,您只需在循环中执行查询。但是使用MVC我们不应该那样做。控制器在列表中传递列表的最佳模式

在JSP中,我需要创造这样的:

Business 
    Project 1 
    Item 
    Item 
    Project 2 
    Item 
    Item 
    Item 
    Project 3 
    Item 
Business 2 
... 

什么结构,我需要在控制器中创建?名单不会去做。该列表需要包含不同的对象类型。我如何构建JSP中的循环?

线上是否存在描述这些模式的资源?

回答

0

为什么你不使用类似

class Business 
    String businessName; 
    List<Projects> projects 

class Projects 
    String projectName; 
    List<Item> 

class Item 
    String itemName; 

,并传递了request.setAttribute( “业务”,BusinessObject的)

然后在属性迭代。

<c:forEach var="projects" items="${business.projects}"> 
    <tr><td>${projects.name}<td> 
    <c:forEach var="item" items="${projects.item}"> 
    <tr><td>${item.name}<td> 
    </c:forEach> 
</c:forEach> 

请考虑阅读本thread

+0

是否有用,或者是有用的? – Koitoer

相关问题