📄 pager.vm
字号:
#### Copyright(C) 2002 Javanovic Software (http://www.javanovic.com)#### This library is free software; you can redistribute it and/or## modify it under the terms of the GNU Lesser General Public## License as published by the Free Software Foundation; either## version 2.1 of the License, or (at your option) any later version.#### This library is distributed in the hope that it will be useful,## but WITHOUT ANY WARRANTY; without even the implied warranty of## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU## Lesser General Public License for more details.#### You should have received a copy of the GNU Lesser General Public## License along with this library; if not, write to the Free Software## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA##//---------------------------------------------------------// Application: $property.Name// Author : $property.Author// File : Pager.java//// Copyright $year $property.Company// Generated at $date.Time// using Karapan Sapi Struts Generator// Visit http://www.javanovic.com//---------------------------------------------------------package ${build.Package}.util;import java.util.*;public class Pager { private static int MAX_PAGE_INDEX = 15; private static String HEADER = "Result page"; static { ResourceBundle prop = ResourceBundle.getBundle("resources.application"); try { HEADER = prop.getString("pager.header.title"); } catch (Exception e) { } try { MAX_PAGE_INDEX = Integer.parseInt(prop.getString("pager.max.page.index")); } catch (Exception e) { } } public static String generate(int offset, int length, int size, String url) { if (length > size) { String pref; if (url.indexOf("?") > -1) { pref = "&"; } else { pref = "?"; } String header = "<font face='Helvetica' size='-1'>"+HEADER+": "; if (offset > 0) { header += " <a href=\""+url+pref+"pager.offset="+(offset-size)+"\">[<< Prev]</a>\n"; } int start; int radius = MAX_PAGE_INDEX/2*size; if (offset < radius) { start = 0; } else if(offset < length-radius) { start = offset - radius; } else { start = (length/size-MAX_PAGE_INDEX)*size; } for(int i=start;i<length && i < start + MAX_PAGE_INDEX*size;i+=size) { if (i == offset) { header += "<b>"+(i/size+1)+"</b>\n"; } else { header += " <a href=\""+url+pref+"pager.offset="+i+"\">"+(i/size+1)+"</a>\n"; } } if(offset < length - size) { header += " <a href=\""+url+pref+"pager.offset="+((int)offset+(int)size)+"\">[Next >>]</a>\n"; } header += "</font>"; return header; } else { return ""; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -