如何使用分页和分页样式
2012-11-29 16:33
246 查看
分页组件的使用:
第一步:将util文件夹复制到项目 的SRC文件下面
第二步:将mypage.tld文件复制到web-inf文件夹下面
第三步:打开需要分页的页面,在page指令下方添加导入标签库的代码:
<%@taglib uri="/WEB-INF/MyPage.tld" prefix="pt"%>
在需要显示分页的地方,添加如下代码:
<pt:page pageIndex="当前第几页" url="当前页面地址?" pageMax="总的页数"/>
我们在action中所要使用的代码:
//分页所用
private String page; //前台传过来的页指针
private int pageIndex=1; //当前页
private int pageMax;// 总页数
此处省略这三个属性的set和get方法
/**
* 获取当前页面的方法
* @return
*/
public String getpage(){
if (page != null && !page.equals(""))
pageIndex=Integer.parseInt(page); // 当前页
int size = 2; // 每页的记录数
int count = biz.queryByAll().size();// 总记录数
pageMax = count % size == 0 ? count / size : count / size + 1;// 总页数
list = biz.queryByPage(pageIndex, size);
return "ok";
}
/**
* 默认执行的方法,并把部门和角色的信息传入到页面
* @return
*/
public String execute()
{
queryAllDept();
queryAllRole();
list=biz.queryByAll();//查询出员工的全部记录
getpage(); //调用分页的方法,我们这边如果在默认的execute()方法中如果没有调用,那么我们在<pt:page pageIndex="当前第几页"
url="当前页面地址?" pageMax="总的页数"/>中的url中要加上getpage方法比如:url="SysEmp_getpage?"
return "ok";
}
//分页样式
DIV.digg {padding: 6px;margin:13px 3px 15px 3px;text-align: right;}
DIV.digg A {border: #cfd0c8 1px solid; padding:2px 5px;margin: 2px;color: #000;font-size:12px;line-height:22px;text-decoration: none;}
DIV.digg A:hover {background-color: #aed256;color: #FFF;text-decoration: none;}
DIV.digg A:active{ color: #000;border: #cfd0c8 1px solid;}
DIV.digg SPAN.current {border: #cfd0c8 1px solid;padding: 2px 4px;font-weight: bold;margin: 2px;color: #fff;background-color: #A6D0E7;}
DIV.digg SPAN.disabled {border: #eee 1px solid;padding: 5px;margin: 2px;color: #ddd;}
然后在要分页的页面写如下即可:
<tr>
<td height="40">
<table width="100%" border="0" cellspacing="0" cellpadding="0" cellspacing="1" bgcolor="#D1EBF9">
<tr>
<td ><div class="digg"><span class="current"><pt:page pageIndex="${pageIndex}"
url="SysEmp?" pageMax="${pageMax}"/></span></div></td>
</tr>
</table>
</td>
</tr>
上面的红色部门为关键之处(其中url要特别注意,看是否要加上getpage方法,url是struts.xml文件中指向当前页面的action名字)
第一步:将util文件夹复制到项目 的SRC文件下面
第二步:将mypage.tld文件复制到web-inf文件夹下面
第三步:打开需要分页的页面,在page指令下方添加导入标签库的代码:
<%@taglib uri="/WEB-INF/MyPage.tld" prefix="pt"%>
在需要显示分页的地方,添加如下代码:
<pt:page pageIndex="当前第几页" url="当前页面地址?" pageMax="总的页数"/>
我们在action中所要使用的代码:
//分页所用
private String page; //前台传过来的页指针
private int pageIndex=1; //当前页
private int pageMax;// 总页数
此处省略这三个属性的set和get方法
/**
* 获取当前页面的方法
* @return
*/
public String getpage(){
if (page != null && !page.equals(""))
pageIndex=Integer.parseInt(page); // 当前页
int size = 2; // 每页的记录数
int count = biz.queryByAll().size();// 总记录数
pageMax = count % size == 0 ? count / size : count / size + 1;// 总页数
list = biz.queryByPage(pageIndex, size);
return "ok";
}
/**
* 默认执行的方法,并把部门和角色的信息传入到页面
* @return
*/
public String execute()
{
queryAllDept();
queryAllRole();
list=biz.queryByAll();//查询出员工的全部记录
getpage(); //调用分页的方法,我们这边如果在默认的execute()方法中如果没有调用,那么我们在<pt:page pageIndex="当前第几页"
url="当前页面地址?" pageMax="总的页数"/>中的url中要加上getpage方法比如:url="SysEmp_getpage?"
return "ok";
}
//分页样式
DIV.digg {padding: 6px;margin:13px 3px 15px 3px;text-align: right;}
DIV.digg A {border: #cfd0c8 1px solid; padding:2px 5px;margin: 2px;color: #000;font-size:12px;line-height:22px;text-decoration: none;}
DIV.digg A:hover {background-color: #aed256;color: #FFF;text-decoration: none;}
DIV.digg A:active{ color: #000;border: #cfd0c8 1px solid;}
DIV.digg SPAN.current {border: #cfd0c8 1px solid;padding: 2px 4px;font-weight: bold;margin: 2px;color: #fff;background-color: #A6D0E7;}
DIV.digg SPAN.disabled {border: #eee 1px solid;padding: 5px;margin: 2px;color: #ddd;}
然后在要分页的页面写如下即可:
<tr>
<td height="40">
<table width="100%" border="0" cellspacing="0" cellpadding="0" cellspacing="1" bgcolor="#D1EBF9">
<tr>
<td ><div class="digg"><span class="current"><pt:page pageIndex="${pageIndex}"
url="SysEmp?" pageMax="${pageMax}"/></span></div></td>
</tr>
</table>
</td>
</tr>
上面的红色部门为关键之处(其中url要特别注意,看是否要加上getpage方法,url是struts.xml文件中指向当前页面的action名字)
相关文章推荐
- HTML初学---如何使用样式
- 如何使用HibernateTemplate进行分页功能
- 如何在应用程序中使用Silverlight Toolkit中的主题样式
- MyBatis中如何使用PageHelper插件实现 分页
- yii使用bootstrap分页样式的实例
- GridView使用自带分页功能时分页方式及样式PagerStyle
- C# GridView 在使用分页时,如何不显示底部自动添加的分页风格
- 如何在Sql Server上使用一条SQL查询结果总数并且分页
- Flex中如何通过设置fontFamily样式在NumericStepper控件中使用嵌入字体的例子
- MVC如何使用开源分页插件shenniu.pager.js
- 从零开始前端学习[47]:如何使用javascript来操作行内样式或者属性浅析
- 如何使用Mybatis来实现分页功能的两种方法
- 如何使用SQL Server2005在web中进行分页
- 视图控制器父类是使用Xib创建的,子类如何继承父类的样式
- 详解MVC如何使用开源分页插件(shenniu.pager.js)
- 如何使用变量给数据源控件参数赋值、如何动态增减数据源控件参数并支持分页
- phpcms中如何修改分页样式?
- FreeCMS商业版如何修改分页样式?
- CakePHP: 如何在$html->link中使用自定义样式
- 不使用“DataSourceControl DataSource”的情况下如何分页和排序