pageno

时间:2024-06-29 06:46:02编辑:奇事君

JSP分页要用2个方法,我怀疑我写的不对,有没有源码?

首先得来个实体类(存储分页的信息,我起名称叫Page)
import java.util.ArrayList;
import java.util.List;public class Page {
private int totalPage = 1;/**
* 前一页
*/
private int prePage = 1;/**
* 下一页
*/
private int nextPage = 1;/**
* 总记录数
*/
private int totalRec = 0;/**
* 默认每页记录数
*/
private final int defaultPageSize = 10;/**
* 每页记录数
*/
private int pageSize = defaultPageSize;/**
* 当前页码
*/
private int pageIndex = 1;/**
* 全部页码,从1开始
*/
private int[] pageNumbers;public int getPageIndex() {
return pageIndex;
}public void setPageIndex(int pageIndex) {
this.pageIndex = pageIndex > 0 ? pageIndex : 1;
}public int getNextPage() {
return nextPage;
}public void setNextPage(int nextPage) {
this.nextPage = nextPage > this.totalPage ? this.totalPage : nextPage;
}public int getPageSize() {
return pageSize;
}public void setPageSize(int pageSize) {
this.pageSize = pageSize > 0 ? pageSize : 10;
}public int getPrePage() {
return prePage;
}public void setPrePage(int prePage) {
this.prePage = prePage < 1 ? 1 : prePage;
}public int getTotalPage() {
return totalPage;
}public void setTotalPage(int totalPage) {
this.totalPage = totalPage > 0 ? totalPage : 1;
}public int getTotalRec() {
return totalRec;
}public void setTotalRec(int totalRec) {
this.totalRec = totalRec > -1 ? totalRec : 0;
}public int[] getPageNumbers() {
return pageNumbers;
}public void setPageNumbers(int[] pageNumbers) {
this.pageNumbers = pageNumbers;
}
}
==============实体类有了,我们得在写一个公共的DAO方法(也就是每一个用到分页的地方都会调用这个)================public List findPageByQuery(final String queryString,
final Object[] parameters, final Page pageInfo) {
return (List) getHibernateTemplate().execute(new HibernateCallback()//这里使用了匿名内部类
{
public Object doInHibernate(Session session)//Spring进行事务维护 省去每次创建session和关闭session
throws HibernateException
{
Query query = session.createQuery(queryString);
if (parameters != null)
{
for (int i = 0; i < parameters.length; i++)
{
query.setParameter(i, parameters[i]);
}
}
ScrollableResults sr = query.scroll();
sr.last();
int totalCount = sr.getRowNumber();
int startIndex = (pageInfo.getPageIndex() - 1)
* pageInfo.getPageSize();
query.setMaxResults(pageInfo.getPageSize());
query.setFirstResult(startIndex);
int totalRec = totalCount + 1;
pageInfo.setTotalRec(totalRec);
int totalPage = (totalRec % pageInfo.getPageSize() == 0) ? (totalRec / pageInfo
.getPageSize())
: (totalRec / pageInfo.getPageSize()) + 1;
int[] pageNumbers = new int[totalPage];
for (int i = 0; i < totalPage; i++)
{
pageNumbers[i] = (i + 1);
}
pageInfo.setPageNumbers(pageNumbers);
pageInfo.setTotalPage(totalPage);
pageInfo.setPageSize(pageInfo.getPageSize());
pageInfo.setPageIndex(pageInfo.getPageIndex());
pageInfo.setPrePage(pageInfo.getPageIndex() - 1);
pageInfo.setNextPage(pageInfo.getPageIndex() + 1);
return query.list();
}
}, true);
}
=================至此我们的工作就完成了一半了 ,接下了就改写具体的方法了,来调用我们的公工分页方法public List getUU(int lexample,Page pageInfo)
{
/*ApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml");
dao = (DaoImpl) context.getBean("Dao");
System.out.print(dao);*/ //自己测试时候可以使用
List list = null;
if (pageInfo == null)
pageInfo = new Page();
try
{
hql="SELECT exa FROM Example exa WHERE 1=1 AND exa.LExample="+lexample;
list = this.getCommonDAO().findPageByQuery(hql, null, pageInfo);
} catch (Exception ex)
{
System.out.println(ex);
}
return list;
}=============接下来就是action中调用了===============public ActionForward getMore(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ExampleForm exampleForm = (ExampleForm) form;// TODO Auto-generated method stub
List list = new ArrayList();
try
{
//pageInfo = (PageInfo) request.getAttribute("pageInfo");
String type=request.getParameter("type");
//类别编号
int typeId=0;
//页码编号
String page=request.getParameter("page");
if(page==null)
{page="1"; }
if(type==null) {
//默认显示女的
type="2";
}


System.out.println("action...........................");
pageInfo.setPageIndex(Integer.parseInt(page));
pageInfo.setPageSize(20);
typeId=Integer.parseInt(type);
// pageInfo.setPageIndex(Integer.parseInt(request.getParameter("Index")));

list = this.exampleBiz.getUU(typeId,pageInfo);
if(list.size()!=0)
{
request.setAttribute("list", list);
request.setAttribute("pageInfo", pageInfo);
}
}catch
(Exception ex)
{
ex.printStackTrace();
}
return mapping.findForward("more");
}======下面是页面,我们的工作马上就完了。<%String nowPage ;
String type;
int total;

nowPage=request.getParameter("page");
if(nowPage==null)
{nowPage="1";}
type=request.getParameter("type"); //这个是我项目中的类别,没必要的
if(type==null) {
type="2";
}
int curPage=Integer.parseInt(nowPage);
int typeId=Integer.parseInt(type);
System.out.println(typeId+"------------------------------------");
if((Page)request.getAttribute("pageInfo") == null){
total = 1;
} else {
total = ((Page)request.getAttribute("pageInfo")).getTotalPage();
if(curPage>((Page)request.getAttribute("pageInfo")).getTotalPage()) {
curPage=total;
}
}

%>




${example.account.name }
明星指数:254179
送鲜花
扔鸡蛋






">首页 |
&type="">上一页 |
total?total:curPage+1%>&type="">下一页 |
">末页
当前第页 转到第 "> <%
for(int toPage = 1; toPage<=total; toPage++) {
%>


selected

>


<%
}
%>

共页 ${pageInfo.pageIndex}
OK!,现在我们的分页就行了,赶快试试吧!


excel vba 怎么查看当前工作表可打印的总页数,和某一页的所在的页数,

Sub 定义页码及总页数名称()
'
' 定义页码及总页数名称 Macro
' 宏由 cbtaja 录制,时间: 2010-5-12
'

'
ActiveWorkbook.Names.Add Name:="ColFirst", RefersToR1C1:= _
"=GET.DOCUMENT(61)" '判断打印顺序的设置类型
ActiveWorkbook.Names.Add Name:="lstRow", RefersToR1C1:= _
"=GET.DOCUMENT(10)" '本工作表已用到的最大行数
ActiveWorkbook.Names.Add Name:="lstColumn", RefersToR1C1:= _
"=GET.DOCUMENT(12)" '本工作表已用到的最大列数
ActiveWorkbook.Names.Add Name:="hNum", RefersToR1C1:= _
"=IF(ISERROR(FREQUENCY(GET.DOCUMENT(64),Row())),0,FREQUENCY(GET.DOCUMENT(64),Row()))" 'hNum为本单元格上方的水平分页符个数
ActiveWorkbook.Names.Add Name:="vNum", RefersToR1C1:= _
"=IF(ISERROR(FREQUENCY(GET.DOCUMENT(65),Column())),0,FREQUENCY(GET.DOCUMENT(65),Column()))" ''本单元格左边的垂直分页个数
ActiveWorkbook.Names.Add Name:="hSum", RefersToR1C1:= _
"=IF(ISERROR(FREQUENCY(GET.DOCUMENT(64),lstRow)),0,FREQUENCY(GET.DOCUMENT(64),lstRow))" ''本工作表最后一个单元格上方的水平分页符个数
ActiveWorkbook.Names.Add Name:="vSum", RefersToR1C1:= _
"=IF(ISERROR(FREQUENCY(GET.DOCUMENT(65),lstColumn)),0,FREQUENCY(GET.DOCUMENT(65),lstColumn))" ''本工作表最后一个单元格左边的垂直分页个数
ActiveWorkbook.Names.Add Name:="ThisPageNo", RefersToR1C1:= _
"=IF(ColFirst,(hSum+1)*vNum+hNum+1,(vSum+1)*hNum+vNum+1)*ISNUMBER(NOW())" '单元格所在页码
ActiveWorkbook.Names.Add Name:="PagesCount", RefersToR1C1:= _
"=GET.DOCUMENT(50)*ISNUMBER(NOW())" '本工作表的总页数
End Sub


SQL存储过程 ')' 附近有语法错误。

执行存储过程的时候,参数不能是GETDATE()这样的函数,需要定义一个变量,把函数的值放到变量中才可以。
exec InsertData 'sdf','sefe' ,'frv' ,'adfe' ,getdate(),'saefa' ,'aea' ,'1';
你可以试试,把getdate()换了,就不是报这个错误了,你要用getdate(),就在过程里面定义变量,赋值为getdate()


上一篇:诸葛神算解签

下一篇:earise