java web 通用的分页组件
<div style="" class="Section1">通用的分页组件有时候找到一个合适的web表格分页组件真是一件痛苦的事情,要么是没有完全封装的分页方法,使用起来比较麻烦,不够方便,要么使用方便,但很难同项目结合,也有许多开源分页组件,功能非常强大,但使用起来有很多问题,有些不好与系统结合,有些不好扩展,但总感觉有些浮肿,很多功能不够实用,也没多大意义,就此尝试写了一个分页组件,够用了,但也有不少问题,望大家共同修正.
1、 HTML元素java封装:
为了操作方便起见,
package commons.page;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
public class HtmlElement {
private String tagName;
private Map<String, String> attributes = new HashMap<String, String>();
private List<HtmlElement> children = new ArrayList<HtmlElement>();
private String value = "";
private String text = "";
public HtmlElement(String tagName) {
this.tagName = tagName;
}
public void setValue(String value) {
this.value = value;
}
public List<HtmlElement> getChildren() {
return children;
}
public void addChild(HtmlElement element) {
this.children.add(element);
}
public void addAttribute(String name, String value) {
this.attributes.put(name, value);
}
public String getAttributeValue(String name) {
return this.attributes.get(name);
}
@Override
public String toString() {
return this.toHtml();
}
public String toHtml() {
StringBuffer sb = new StringBuffer();
sb.append("<");
sb.append(this.tagName);
sb.append(this.getAttr());
sb.append(">");
sb.append(this.value);
for (HtmlElement e : this.children) {
sb.append(e.toHtml());
}
sb.append(this.text);
sb.append("</");
sb.append(this.tagName);
sb.append(">");
return sb.toString();
}
protected String getAttr() {
StringBuffer sb = new StringBuffer();
Set<Entry<String, String>> attr = this.attributes.entrySet();
for (Entry<String, String> entry : attr) {
sb.append(" ");
sb.append(entry.getKey());
sb.append("=\"");
sb.append(entry.getValue());
sb.append("\"");
}
return sb.toString();
}
public void setText(String text) {
this.text = text;
}
}
页:
[1]