JAVA中分页怎么写,body
当前搜索条件:
c:if test="${cond==null}"空/c:if
c:if test="${cond!=null}"${cond}/c:if
form action="page" method="post"
input type="text" name="name"/
input type="submit" value="https://www.04ip.com/post/按名字模糊搜索" /
/form
table
tr
td商品编号/td
td类型编号/td
td商品名称/td
td商品说明/td
td商品图片/td
td商品日期/td
td详细图片/td
/tr
!-- 循环遍历ps对象中的ListAddress集合 --
c:forEach items="${sps.infos}"var="ad"
tr
td${ad.shopId}/td
td${ad.typeId}/td
td${ad.shopName}/td
td${ad.shopSay}/td
td${ad.shopPrice}/td
td${ad.defaultPic}/td
td${ad.upMetailDate}/td
/tr
/c:forEach
/table
a href="https://www.04ip.com/post/page?cp=1"首页/a
a href="https://www.04ip.com/post/page?cp=${(sps.currentPage-1)=1?1:(sps.currentPage-1)}"上页/a
a href="https://www.04ip.com/post/page?cp=${(sps.currentPage+1)=(sps.countPage)?(sps.countPage):(sps.currentPage+1)}"下页/a
a href="https://www.04ip.com/post/page?cp=${sps.countPage}"末页/a
/body
这是我之前写的DEMO,对应的把属性改成你写好的ACTION就可以了
谁能给我个完整的java 分页代码 谢谢了import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import com.lqh.dao.db.DBCon;
public class PageDAO {
public static final String Text = "text";
public static final String Image = "image";
public static final String BbsText = "bbstext";
public static final String BbsImage = "bbsimage";
private HttpServletRequest request;
private int currentpage = 1; // 当前是第几页
private int pagecount = 0; // 一共有多少页
private int rscount = 0; // 一共有多少行
private int pagesize = 10; // 每页有多少行[默认为20行]
public PageDAO(HttpServletRequest request) {
this.request = request;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage) {
this.currentpage = currentpage;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getRscount() {
return rscount;
}
public void setRscount(int rscount) {
this.rscount = rscount;
}
/**
* 传入SQL语句获取总记录数
*/
public int getRsCountForRs(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
rs.last();
this.rscount = rs.getRow();
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);
}
return this.rscount;
}
public int getRsCountForSQL(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
this.rscount = rs.getInt("rscount");
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
推荐阅读
- js获取文本域的值,js获取文本域的内容
- 新媒体创业如何盈利,新媒体创业盈利模式有哪些?
- 恐怖游戏冒险解谜攻略视频,恐怖冒险解谜游戏大全
- 抖音游戏直播声音关闭了,抖音游戏直播怎么关闭声音
- python看函数参数 python函数参数类型检查
- Python字符串中剔除汉字,python字符串去掉汉字
- css取消文本居中,css取消字体样式
- vb.net控件数据绑定 vb60中的数据绑定控件必须
- jquery写无缝轮播,jquery图片轮播无缝连接