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;
}
}
您有什麼問題的頂部? – Arvind 2014-12-05 05:11:51
它不會在我的表格中顯示任何內容。我已驗證列表中有值,但不會顯示在表格中。 – rammaidy 2014-12-05 05:26:16
只是爲了驗證代碼,你可以嘗試添加屬性到'HttpSession'嗎? – Arvind 2014-12-05 05:30:09