package com.paging;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import com.user.User;
import sun.nio.cs.US_ASCII;
public class Paging {
final int num=3;
@Resource
SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public List<User> paging(int index) {
String hql = "from User";
Query query = sessionFactory.getCurrentSession().createQuery(hql);
query.setFirstResult((index-1)*num);
query.setMaxResults(num);
return query.list();
}
}
package com.web;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.paging.Paging;
import com.user.User;
@Controller
@RequestMapping("/Page")
public class Web {
@Resource
Paging paging;
public void setPaging(Paging paging) {
this.paging = paging;
}
@RequestMapping("/page")
public String page(Model model,int index) {
List<User> list = paging.paging(index);
model.addAttribute("list", list);
return "index";
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>" rel="external nofollow" >
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" >
-->
</head>
<body>
<h1><a href="/Paging/Page/page?index=1" rel="external nofollow" >1</a></h1>
<h1><a href="/Paging/Page/page?index=2" rel="external nofollow" >2</a></h1>
<h1><a href="/Paging/Page/page?index=3" rel="external nofollow" >3</a></h1>
<c:if test="${!empty list }">
<c:forEach items="${list}" var="list">
${list.name}
${list.adderss}
</c:forEach>
</c:if>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有