public List selectAllBook(int userId,int rowNum1){
List list =new ArrayList();
int rowBegin = 0;
if(rowNum1>1){
rowBegin = 5*(rowNum1-1);
}
String sql ="select * FROM (select ROW_NUMBER() Over(order by id) as rowNum, * from book where userId=?) as table1 " +
"where rowNum> ="+rowNum1+" and rowNum<="+rowBegin+"";
try {
conn = this.getConn();
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, userId);
rs = pstmt.executeQuery();
while(rs.next()){
Book book = new Book();
book.setId(rs.getInt("Id"));
book.setName(rs.getString("name"));
book.setSex(rs.getString("sex"));
book.setPhone(rs.getString("phone"));
book.setMobilePhone(rs.getString("mobilePhone"));
list.add(book);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.CloseAll(conn, pstmt, rs);
}
return list;
}//数据
//Servlet
int y = Integer.parseInt(request.getParameter("page"));
request.setCharacterEncoding("gbk");
response.setContentType("text/html;gbk");
HttpSession session = request.getSession(false);
Users user = (Users)session.getAttribute("users");
BookBo bb = new BookBo();
String str = request.getParameter("relation");
List list =null;
list = bb.selectAllBook(user.getUserId(),y);//JSP页面
<%
int size =5;
int j=1;
String str = request.getParameter("page");//这里老是空 为什么 不晓得怎么搞分页了
if(str!=null){
j = Integer.parseInt(str);
}
int prePage = j;
int nextPage = j;
List list1 =(List)request.getAttribute("bb1");
if(list1.size()==size){
nextPage = j+1;
}
if(j>2){
prePage=j-1;
}
for(int i=0;i<list1.size();i++){
Book book = (Book)list1.get(i);
%>
<td><a href="bookContent.jsp?page=<%=prePage %>">上一页</a><a href="bookContent.jsp?page=<%=nextPage %>">下一页</a></td>
List list =new ArrayList();
int rowBegin = 0;
if(rowNum1>1){
rowBegin = 5*(rowNum1-1);
}
String sql ="select * FROM (select ROW_NUMBER() Over(order by id) as rowNum, * from book where userId=?) as table1 " +
"where rowNum> ="+rowNum1+" and rowNum<="+rowBegin+"";
try {
conn = this.getConn();
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, userId);
rs = pstmt.executeQuery();
while(rs.next()){
Book book = new Book();
book.setId(rs.getInt("Id"));
book.setName(rs.getString("name"));
book.setSex(rs.getString("sex"));
book.setPhone(rs.getString("phone"));
book.setMobilePhone(rs.getString("mobilePhone"));
list.add(book);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.CloseAll(conn, pstmt, rs);
}
return list;
}//数据
//Servlet
int y = Integer.parseInt(request.getParameter("page"));
request.setCharacterEncoding("gbk");
response.setContentType("text/html;gbk");
HttpSession session = request.getSession(false);
Users user = (Users)session.getAttribute("users");
BookBo bb = new BookBo();
String str = request.getParameter("relation");
List list =null;
list = bb.selectAllBook(user.getUserId(),y);//JSP页面
<%
int size =5;
int j=1;
String str = request.getParameter("page");//这里老是空 为什么 不晓得怎么搞分页了
if(str!=null){
j = Integer.parseInt(str);
}
int prePage = j;
int nextPage = j;
List list1 =(List)request.getAttribute("bb1");
if(list1.size()==size){
nextPage = j+1;
}
if(j>2){
prePage=j-1;
}
for(int i=0;i<list1.size();i++){
Book book = (Book)list1.get(i);
%>
<td><a href="bookContent.jsp?page=<%=prePage %>">上一页</a><a href="bookContent.jsp?page=<%=nextPage %>">下一页</a></td>
解决方案 »
- 我已经重写hashCode方法和equals方法还是不能判断两个重复的对象?
- jfreechart 生成折线统计图 两条折线如何让其中一条显示数据另一条不显示...
- 关于jdk版本我问题
- 真的很急急急急 怎样解决由request.getQueryString()获得中文参数乱码问题 求高手 真的很急急急急 急急急
- struts中获得application
- 调用过程异常
- 小菜读取数据库表里的所有数据问题?
- Tomcat下最初级的问题!!!高手前来指导!!!
- 请教下压缩
- Tomcat连接池问题:Cannot create JDBC driver of class '' for connect URL 'null'
- 【求助】有关java计时问题
- java做水晶报表一般都用那些技术,能否提供些demo
package s2jsp.bysj.impl;
import java.util.*;
public class Paginate {
private int pageNo;
private int pageSize;
private int pageCount;
private int totalCount; public Paginate(int pageNo, int pageSize) {
super();
this.pageNo = pageNo;
this.pageSize = pageSize;
}
public Paginate() {
super();
// TODO Auto-generated constructor stub
}
public Paginate(int pageNo, int pageSize, int pageCount, int totalCount) {
super();
this.pageNo = pageNo;
this.pageSize = pageSize;
this.pageCount = pageCount;
this.totalCount = totalCount;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public List Pagging(List all)
{
// if(this.pageSize<=all.size())
// {
// return all;
// }
if(all.size()==0)
{
return null;
}
if(this.pageSize<0)
{
this.pageSize=5;
}
this.totalCount=all.size();
this.pageCount=this.totalCount/this.pageSize;
if(this.totalCount%this.pageSize!=0)
{
this.pageCount++;
}
if(pageNo<0)
{
pageNo=1;
}
if(pageNo>pageCount)
{
pageNo=pageCount;
}
List lst=new ArrayList();
for (int i = (this.pageNo-1)*this.pageSize; i < this.pageNo*this.pageSize; i++) {
if(i>=all.size())
{
break;
}
lst.add(all.get(i));
}
return lst;
}}