Spring mvc hibenate 페이지

7882 단어 spring mvc
예전 에 했 던 프로젝트 는 모두 SSH 프레임 워 크 였 습 니 다. 물론 페이지 매개 변수 전달 은 '... /............................................................
어 머, 드디어 끝났어 요. 왜 잘 모 르 겠 어 요?
 
1: application. xml 설정 정보 (부분)
 
 
    <bean id="test3Service" class="test.Test3ServiceImpl">
		<property name="sessionFactory" ref="sessionFactory">              </property>
    </bean>  

 
 
2: application - security. xml 설정 은 다음 과 같 습 니 다 (부분)
 
 
<security:intercept-url pattern="/*.htm" access="IS_AUTHENTICATED_REMEMBERED"/>

 
 
3: spring - mvc - servlet. xml 설정 은 다음 과 같 습 니 다 (부분)
 
 
    <bean name="/Test3.htm" class="test.Test3Controller">
    	<property name="test3Service" ref="test3Service"/>
    </bean> 

 
 
4: Test3Service 인터페이스
 
 
public interface Test1Service {
	
	public List<Expert> findExpertList();
	
}
 
 
5: Test3ServiceImpl 실현
 
 
public class Test3ServiceImpl extends HibernateDaoSupport implements
		Test3Service {

	@Override
	public PaginationSupport findPageByQuery(int pageSize,
			int startIndex) {
		Session session = this.getHibernateTemplate().getSessionFactory().openSession();
		String hsql = " from Expert e order by id desc";
		Query query  =  session.createQuery(hsql);
        int totalCount=query.list().size();
        query.setFirstResult(startIndex); 
        query.setMaxResults(pageSize); 
        List items  = query.list();
        PaginationSupport ps = new PaginationSupport(items,
    		 totalCount, pageSize, startIndex);
        session.close();
        return ps;
	}

}
 
 
6:Test3Controller  
 
 
 
public class Test3Controller implements Controller {

	private static Logger log = Logger.getLogger("Test3Controller");
	private Test3Service test3Service;
	private PaginationSupport userPage;
	private int pageSize = 10;
	private int startIndex;
	private List experts;

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.info("Test3Controller     !");
		String i = request.getParameter("startIndex");
		if (i != null || "".equals(i)) {
			startIndex = Integer.parseInt(i);
			System.out.println("ii:" + i + "startIndex:" + startIndex);
		}

		userPage = test3Service.findPageByQuery(pageSize, startIndex);
		request.setAttribute("userPage", userPage);
		return new ModelAndView("Test3", "experts", userPage.getItems());
	}

	public Test3Service getTest3Service() {
		return test3Service;
	}

	public void setTest3Service(Test3Service test3Service) {
		this.test3Service = test3Service;
	}

	public PaginationSupport getUserPage() {
		return userPage;
	}

	public void setUserPage(PaginationSupport userPage) {
		this.userPage = userPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}

	public List getExperts() {
		return experts;
	}

	public void setExperts(List experts) {
		this.experts = experts;
	}

}

 
 
 
7:Test3.jsp
 
 
<%@ page language="java" contentType="text/html; charset=gbk"
	pageEncoding="GBK"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link type="text/css" rel="stylesheet" href="../css/panel.css">
		<title>      </title>
		<script type="text/javascript">
			function setStartIndex(startIndex){
				alert(startIndex);
				location.href='Test3.htm?startIndex='+startIndex; 
			}
		
		</script>
	</head>

	<body>
		<table border="1" cellspacing="0" cellpadding="0" width="100%"
			align="center">
			<tr>
				<td>
					<br>
					<table class="list" border="1" width="100%">
						<tr align="center" height="25">
							<td width="4%">
								<strong>  </strong>
							</td>
							<td width="7%">
								<strong>    </strong>
							</td>
						</tr>

						<c:forEach var="q" items="${experts}" varStatus="status">
							<tr>
								<td>
									${q.id}
								</td>
								<td>
									${q.description}
								</td>
							</tr>
						</c:forEach>

					</table>
				</td>
			</tr>
		</table>
		<c:if test="${!empty userPage}">
      ${userPage.totalCount}   
    		 <c:choose>
				<c:when test="${userPage.startIndex ne '0'}">
					<a href="Test3.htm?startIndex=0">  </a>
				</c:when>
				<c:otherwise>
       				  
     			 </c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${userPage.previousIndex lt userPage.startIndex}">
					<!-- 
					<a href="Test3.htm?startIndex=${userPage.previousIndex }">   </a>
					 -->
					 <a href="javascript:setStartIndex(${userPage.previousIndex })">   </a>
				</c:when>
				<c:otherwise>
       				   
     			 </c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${userPage.nextIndex>userPage.startIndex}">
				<!-- - 
					<a href="Test3.htm?startIndex=${userPage.nextIndex}">   </a>
					-->
					<a href="javascript:setStartIndex(${userPage.nextIndex})">   </a>
				</c:when>
				<c:otherwise>
          
      </c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${userPage.lastIndex eq userPage.startIndex}">
           
      </c:when>
				<c:otherwise>
				<!-- 
					<a href="Test3.htm?startIndex=${userPage.lastIndex}">    </a>
					 -->
					 <a href="javascript:setStartIndex(${userPage.lastIndex})">    </a>
				</c:otherwise>
			</c:choose>
		</c:if>
	</body>
</html>

좋은 웹페이지 즐겨찾기