2016-06-01 9 views
-3

私はSpringを初めて使用しています。DAOで複数のレコードをフェッチしようとしています。その後、コントローラに戻ってサービスに戻し、コントローラレイヤーをJSPページに表示する必要があります。私はどのようにコードすることができますJDBCテンプレートを使用したくないです。 ??Spring Mvc複数レコードの取得例

public ArrayList<userBean> Manage() 
{ 
    ArrayList<userBean> list = new ArrayList<userBean>(); 
    System.out.println("manage from dao"); 
    try 
    { 
     con=DbConnection.getConnection(); 
     ps=con.prepareStatement("select * from employee_info"); 
     rs=ps.executeQuery(); 
     while(rs.next()) 
     { 
      ub= new userBean(); 
      ub.setNAME(rs.getString("name")); 
      ub.setLASTNAME(rs.getString("lastname")); 
      ub.setPASSWORD(rs.getString("password")); 
      list.add(ub); 
     } 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 




    return list; 
} 

上記のコードはDAOレイヤーです。 userBaenは私のbeanクラスです。 表示したいJSPページが結果なしでロードされています。続き は、事前に

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %> 
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<!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>Manage Results</title> 
</head> 
<body> 
<c:forEach items="${list}" var="l"> 
<tr> 
       <td>${l.name}</td> 
       <td>${l.lastname}</td> 
       <td>${l.password}</td> 
</tr> 

</c:forEach> 
</body> 
</html> 

おかげで私のJSPコードです。

+1

ここでは、いくつかの提案です:1)サイトのルールを読んで、bczこれは、質問は許可されません。 2)このような概念に役立つ一般的な指示を読むことを学ぶ。 3)あなたが助けたいと思っているコードがあれば元に戻ってください。 –

+0

投票を説明していただきありがとうございます。多くの人々が質問に投票しますが、理由は何も答えません。他の人がこのサイトを助ける手助けをする方法を他の人に教えることを実際に気にする人がいるのは良いことです。 – Dale

答えて

0

エラーを修正しました。 。以下 JSPページでは、コントローラ上の私のため

public ArrayList<userBean> Manage() 
    { 
     HttpServletRequest req = null; 
     HttpServletResponse res; 

     ArrayList<userBean> list = new ArrayList<userBean>(); 
     System.out.println("manage from dao"); 
     try 
     { 
      con=DbConnection.getConnection(); 
      ps=con.prepareStatement("select * from employee_info"); 
      rs=ps.executeQuery(); 
      while(rs.next()) 
      { 
       ub= new userBean(); 
       ub.setNAME(rs.getString("name")); 
       ub.setLASTNAME(rs.getString("lastname")); 
       ub.setPASSWORD(rs.getString("password")); 
       list.add(ub); 
      } 
     } 

     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 




     return list; 
    } 

を作品DAOから自分のコード

public ModelAndView Manage(HttpServletRequest request, HttpServletResponse response) 
    { 
     Bean bean = new Bean(); 
     Dao d= new Dao(); 

     try 
     { 
      List<userBean> rows=d.Manage(); 
      request.setAttribute("rows", rows); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
     return new ModelAndView("manageResult"); 

    } 

ある

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
     pageEncoding="ISO-8859-1"%> 
      <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %> 
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
    <jsp:useBean id="TimeDetailBean" class="com.logic.bean.userBean" scope="application" /> 
    <!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>Manage Results</title> 
    </head> 
    <body> 
    <center> 
    <h1>The Employee_Info Results </h1> 
    <table> 
    <tr><th>Name</th><th>Last name</th><th>Password</th></tr> 
    <c:forEach items="${rows}" var="row"> 
    <tr> 
    <td><input type="text" name="name" value=${row.NAME}></td><td><input type="text" name="lastname" value=${row.LASTNAME}></td><td><input type="text" name="password" value=${row.PASSWORD}></td><td><a href="update.do">UPDATE</a><td><a href="delete.do">DELETE</a></td> 
    </tr> 

    </c:forEach> 
    </table> 
    </center> 
    </body> 
    </html> 
関連する問題