Spring mvc hibenate 페이지
7882 단어 spring mvc
어 머, 드디어 끝났어 요. 왜 잘 모 르 겠 어 요?
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>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
@Component와 @Controller의 차이쓸데없이 느껴지던 MVC 계층도, 그냥 되는 거지 싶던 어노테이션도 셀 수 없이 많은 선배 개발자들의 피눈물과 절망, 숨쉬는 내뱉던 그들의 욕지거리와 쌓여가는 재떨이 속 담배꽁초들, 그럼에도 불구하고 끊임 없이 더 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.