很实用的一个ext表格,具有很好的分页功能。
1、写一个bean类:
public class PatroMonitorBean { private String devicename; private String actionname; private String execTime; private String status; public String getDevicename() { return devicename; } public void setDevicename(String devicename) { this.devicename = devicename; } public String getActionname() { return actionname; } public void setActionname(String actionname) { this.actionname = actionname; } public String getExecTime() { return execTime; } public void setExecTime(String execTime) { this.execTime = execTime; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } }
2、写一个ListRange类:
public class ListRange implements Serializable { private Object[] data; private int totalSize; public ListRange(Object[] data, int totalSize) { this.data = data; this.totalSize = totalSize; } public Object[] getData() { return data; } public void setData(Object[] data) { this.data = data; } public int getTotalSize() { return totalSize; } public void setTotalSize(int totalSize) { this.totalSize = totalSize; } }
3、关键类,核心类中的核心方法:sql 语句根据需求
public ListRange getItems(Map conditions) { int start = Integer.parseInt(conditions.get("start").toString()); int pageSize = Integer.parseInt(conditions.get("limit").toString()); List<PatroMonitorBean> infoList = new ArrayList<PatroMonitorBean>(); Connection con = null; Statement stat = null; ResultSet rs = null; String sql = ""; try { con = DataService.getConnection(); stat = con.createStatement(); sql = " "; rs = stat.executeQuery(sql); while (rs.next()) { PatroMonitorBean pmb = new PatroMonitorBean(); String devicename=rs.getString(1); String actionname=rs.getString(2); String execTime=rs.getString(3); String status = rs.getString(4); pmb.setDevicename(devicename); pmb.setActionname(actionname); pmb.setExecTime(execTime); pmb.setExecTime(execTime.substring(0, 19)); if (status.equals("10002")) status = "异常"; pmb.setStatus(status); if (status.equals("10001")) status = "不正常"; pmb.setStatus(status); infoList.add(pmb); } } catch (Exception e) { e.printStackTrace(); } int end = start + pageSize; if (end > infoList.size()) { end = infoList.size(); } List list = infoList.subList(start, end); return new ListRange(list.toArray(), infoList.size()); }
4、jsp页面。需要有DWRProxy.js 把给js类库导入到webRoot下。
5、dwr.xml配置有:
<dwr> <allow> <create creator="new" javascript="patrolMonitor"><!--一般写类名--> <param name="class" value="类路径"/> </create> <convert converter="bean" match="com.eastcom.action.ListRange"/> <convert converter="bean" match="com.eastcom.action.bean类"/> </allow> </dwr>