2014-12-05 82 views
0

我在使用列表数组的对象填充表格时遇到问题。我似乎无法弄清楚我在做什么错误,因为无处不在我看它告诉我按照我的方式去做。在jsp中使用DTO使用弹簧mvc填充表格

这里是我的jsp表:

<table id="budgetTbl" action="" method="post" class="table table-striped table-bordered table-hover"> 
    <thead> 
     <tr> 
      <th>Budget</th> 
      <th>Projected</th> 
      <th>Actual</th> 
     </tr> 
    </thead> 
    <tbody> 
     <c:forEach var="budget" items="${budgets}"> 
      <tr> 
       <td>${budget.budgetName}</td> 
       <td>${budget.budgetAmount}</td> 
       <td>${budget.actual}</td> 
      </tr>  
     </c:forEach> 
    </tbody> 
</table> 

这是在我的控制器代码:

@RequestMapping(value="budget" , method = RequestMethod.GET) 
public String getBudget(@ModelAttribute("user") User user, Model model) { 

    List<Budget> budgets = budgetService.getBudgets(1); 

    model.addAttribute("budgets", budgets); 

    if(user.getLoggedIn()) 
     return "budget"; 
    else 
     return "redirect:login.html"; 

} 

我的豆:

<jsp:useBean id="budget" class="com.lindeman.model.Budget"/>   
<jsp:setProperty name="budget" property="*"/> 

budgetService:

@Service("budgetService") 
public class BudgetServiceImpl implements BudgetService { 

public List<Budget> getBudgets(int dateID) { 

    List<Budget> budgets = new ArrayList<Budget>(); 


    try (CachedRowSet bud = DAO.getAllBudgets(dateID)) { 

     bud.beforeFirst(); 
     while(bud.next()){ 

      Budget budget = new Budget(); 

      budget.setBudgetID(bud.getInt("BudgetID"));    
      budget.setDateID(bud.getInt("DateID"));    
      budget.setBudgetName(bud.getString("BudgetName"));    
      budget.setBudgetAmount(bud.getDouble("BudgetAmount"));    
      budget.setActual(bud.getDouble("Actual")); 

      budgets.add(budget); 

     } 

    } catch (SQLException e) { 
     DataDriver.processException(e); 
    } 


    return budgets; 

} 

} 
+0

您有什么问题的顶部? – Arvind 2014-12-05 05:11:51

+0

它不会在我的表格中显示任何内容。我已验证列表中有值,但不会显示在表格中。 – rammaidy 2014-12-05 05:26:16

+0

只是为了验证代码,你可以尝试添加属性到'HttpSession'吗? – Arvind 2014-12-05 05:30:09

回答

0

你缺少的taglib进口,把它放在JSP

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>