列表从控制器到视图页面为空

时间:2016-11-30 06:38:36

标签: jsp model-view-controller

控制器代码是,我能够迭代列表以确保列表不为空并且工作正常。

@RequestMapping(value="/saveAccount",params={"find"},method=RequestMethod.POST)
public ModelAndView findAccount(@RequestParam("accname") String name)
{
    System.out.println("hello");
    List<Account> list=this.accountService.findByName(name);
    for(Account a:list)
    {
        System.out.println(a.getAccname());
        System.out.println(a.getDescription());
    } 
 ModelAndView mav=new ModelAndView("saveAccount","list", list);
return mav;
}

jsp页面

       <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
     <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
      <%@ page isELIgnored="false" %>
     <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     <html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     <title>Insert title here</title>
     </head>
     <body>
      <h2>AccountList</h2>
      <c:if test="${!empty lists}">

       <table>
       <thead>
         <tr>
           <th width="80">Account Name</th>
           <th width="80">Description</th>
          </tr>
         </thead>
          <tbody>
         <c:forEach var="account" items="${list}" >
           <tr>
             <td><c:out value="${account.accname}"/></td>
             <td>${account.description}</td>

           </tr>
          </c:forEach> 
         </tbody>
       </table> 
      </c:if> 
     </body>
     </html>

1 个答案:

答案 0 :(得分:-2)

以下代码中的建议是,

确保列表不为空。然后,

试试这个..

c:if test =“$ {!empty list}”