分页输出的实体
package com.loongtao.lucene.search.model;
import java.io.Serializable;
public class PageControl implements Serializable, Cloneable {
??? private static final long serialVersionUID = 3686354990469630498L;
??? private String pageName;
??? private String href;
??? private String isThisPage = "0";
??? public String getPageName() {
??????? return pageName;
??? }
??? public void setPageName(String pageName) {
??????? this.pageName = pageName;
??? }
??? public String getHref() {
??????? return href;
??? }
??? public void setHref(String href) {
??????? this.href = href;
??? }
??? public String getIsThisPage() {
??????? return isThisPage;
??? }
??? public void setIsThisPage(String isThisPage) {
??????? this.isThisPage = isThisPage;
??? }
}
? * 搜索引擎检索分页控件
?*
?* @author xiao.bin
?*
public class SearchPageControl {
???
??? public static List<PageControl> getQueryPageControlByApi(ApiObject api) {
??????? List<PageControl> list = new ArrayList<PageControl>();
??????? // 获取当前页
??????? int page = api.getPage();
??????? // 获取所有条数
??????? int allarticleCount = api.getArticlescount();
??????? // 获取当前页面大小
??????? int pagesize = api.getPagesize();
??????? // 计算页数
??????? int countPage = allarticleCount / pagesize;
??????? // 计算是否需要多加一页
??????? if (allarticleCount % pagesize != 0) {
??????????? countPage++;
??????? }
??????? int startX = 1;
??????? // 计算开始位置
??????? if (page > 4 && page <= countPage) {
??????????? startX = page - 4;
??????? }
??????? // 上一页
??????? if (page > 1 && page <= countPage) {
??????????? PageControl c = new PageControl();
??????????? c.setPageName("上一页");
??????????? c.setHref(appendHref(api, page - 1));
??????????? list.add(c);
??????? }
??????? for (int i = startX; i < startX + 10 && i <= countPage; i++) {
??????????? // 判断是否等于当前页
??????????? PageControl c = new PageControl();
??????????? c.setPageName(i + "");
??????????? c.setHref(appendHref(api, i));
??????????? if (i == page) {
??????????????? c.setIsThisPage("1");
??????????? }
??????????? list.add(c);
??????? }
??????? // 上一页
??????? if (page < countPage) {
??????????? PageControl c = new PageControl();
??????????? c.setPageName("下一页");
??????????? c.setHref(appendHref(api, page + 1));
??????????? list.add(c);
??????? }
??????? return list;
??? }
???
??? public static String appendHref(ApiObject api, int page) {
??????? StringBuffer sb = new StringBuffer("?");
??????? if (api.getTitle().length() > 0) {
??????????? sb.append(appendField("title", api.getTitle()));
??????? }
??????? if (api.getContent().length() > 0) {
??????????? sb.append(appendField("content", api.getContent()));
??????? }
??????? sb.append(appendField("page", page + ""));
??????? sb.append("pagesize=" + api.getPagesize());
??????? return sb.toString();
??? }
???
??? public static String appendField(String urlField, String urlValue) {
//urlencode转码
??????? return urlField + "="
??????????????? + StringUtils.StringToUrlEncode(urlValue, StringUtils.UTF8)
??????????????? + "&";
??? }
??? public static void main(String[] args) {
??????? ApiObject api = new ApiObject();
??????? api.setArticlescount("365");
??????? api.setPage("3");
??????? api.setTitle("xiao.bin");
??????? List<PageControl> list = getQueryPageControlByApi(api);
??????? for (PageControl pageControl : list) {
??????????? System.out.println(pageControl.getHref());
??????? }
??? }
}
由action 发送 List<PageControl>? 到页面上.
? struts2 标签 输出
??? <div id="page">
??? ??? ??? ??? ??? ??? ??? <s:iterator? value="#request.pagectr" id="id"?? status="pagelist">
??? ??? ??? ??? ??? ??? ??? ??? <s:if test="%{#id.isThisPage == 1}">
??? ??? ??? ??? ??? ??? ??? ??? ??? <strong>${pageName}</strong>
??? ??? ??? ??? ??? ??? ??? ??? </s:if>
??? ??? ??? ??? ??? ??? ??? ??? <s:else>
??? ??? ??? ??? ??? ??? ??? ??? <a href="<%=basePath%>search/list.html${href}">[${pageName}]</a>
??? ??? ??? ??? ??? ??? ??? ??? </s:else>???
??? ??? ??? ??? ??? ??? ??? ???
??? ??? ??? ??? ??? ??? ??? </s:iterator>
??? ??? ??? ??? ??? ??? </div>
实现效果
[上一页]???? [1]???? 2???? [3]???? [4]???? [5]???? [6]???? [7]???? [8]???? [9]???? [10]???? [下一页]?
详细解决方案
jsp 开发 百度 google 分页控件 struts2 兑现(转)
热度:704 发布时间:2012-09-02 21:00:34.0
相关解决方案
- struts2.xml的action中的result报错,该怎么处理
- (Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决
- struts2 对象属性流入不进去, 报错:target is null for setProperty(null, "x" [Ljava.lang.Stri
- Struts2 <select>上拉框 回显有关问题
- struts2 添加和修改怎么在一个jsp页面实现
- struts2 查询输出的有关问题
- 零配置的有关问题(struts2+Hibernate)
- struts2 神奇有关问题,太神奇了!
- struts2 的<s:iterator>标签展示未完全初始化的数组出现奇怪的有关问题
- struts2 文件下传有关问题
- struts2+ajax请求失败,帮忙看一上
- struts2-json中诠注@JSON(deserialize=false)是什么用?不是阻止JSON反序列化成JAVA对象吗?求解
- struts2 循环累加属性值有关问题
- struts2,hibernate,spring3 常用框架的API CHM版本,该怎么处理
- struts2 将jsp回到到另一个jsp中
- struts2 提交表单不能跳转页面有关问题!action已经执行,但是不能跳转到指定的页面
- struts2,hibernate,spring3 惯用框架的API CHM版本
- Struts2+Spring+JPA+FREEMARKER 登录程序异常
- struts2+Hibernate一个很奇怪的现象,该如何解决
- struts2 action中部分语句被直接跳过不执行. 请教这会是什么原因
- google map有关问题
- struts2+iReport 子表格 急需高手解决,已经困惑三天了!
- import cn.luxh.struts2.entity.Novel 急需的jar包是哪个
- struts2 hibernate 分页有关问题
- struts2 + spring 整合有关问题
- 请教哪里可以上到 struts2-json-plugin-2.1.8的源文件
- struts2+freemarker中文参数乱码有关问题
- struts2 exception,该怎么解决
- struts2 fileupload 下传有关问题
- struts2.3.4+spring3.1+mybats帮忙看看这个有关问题