分享一个封装好的分页实例
1 新建接口
import java.util.List;
public interface PageInterface {
/**
* 根据页数,每页显示行数返回jtable显示信息
* @param page
* @param rows
* @return
*/
public List getTableList(int page, int rows);
}
2 根据路径查找类
public class PageFactory {
/**
* 根据路径查找类
* @param className 路径
* @return
* @throws InstantiationException
* @throws IllegalAccessException
*/
public static PageInterface getClass(String className)
throws InstantiationException, IllegalAccessException {
PageInterface production = null;
try {
production = (PageInterface) Class.forName (className).newInstance();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return production;
}
}
3 根据路径,页数,每页显示行数得到jtable显示的信息
public class PageList {
public List showListOfTable(String a, int page, int rows)
throws InstantiationException, IllegalAccessException {
PageInterface cat = PageFactory.getClass(a);
List list = cat.getTableList(page, rows);
return list;
}
}
4 建立一个model
public class PageButtonTableModel extends DefaultTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
String header[];
List<Object[]> data = new ArrayList<Object[]>();
public PageButtonTableModel() {
}
public List<Object[]> getData() {
return data;
}
public void setData(List<Object[]> data) {
this.data = data;
}
public int getColumnCount() {
return header.length;
}
public String getColumnName(int c) {
return header[c];
}
public Object getValueAt(int row, int column) {
return data.get(row)[column];
}
public boolean isCellEditable(int r, int c) {
return false;
}
public int getRowCount() {
if (data != null) {
return data.size();
} else {
return 0;
}
}
}
5 建立共用模板
public class ButtonPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JButton firstButton = null;
private JButton preButton = null;
private JButton nextButton = null;
private JButton lastButton = null;
private JLabel jLabel = null;
// ====================
private String page;
private List<Object[]> tableData;
private PageButtonTableModel model;
private int totalPage;
private int numberOfPage = 1;
private String className;
private PageList pList = new PageList(); // @jve:decl-index=0:
private int rows;
private JTable jTable;
/**
*
* @param totalPage 总页数
* @param className 类名
* @param rows 每页显示行数
* @param jTable
*/
public ButtonPanel(int totalPage, String className,
int rows, JTable jTable) {
super();
this.totalPage = totalPage;
this.className = className;
this.rows = rows;
this.jTable = jTable;
page = "共 " + totalPage + " 页 当前第 " + numberOfPage + " 页";
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(270, 1, 129, 24));
jLabel.setText(page);
this.setSize(400, 26);
this.setLayout(null);
this.add(getFirstButton(), null);
this.add(getPreButton(), null);
this.add(getNextButton(), null);
this.add(getLastButton(), null);
this.add(jLabel, null);
}
/**
* This method initializes firstButton
*
* @return javax.swing.JButton
*/
private JButton getFirstButton() {
if (firstButton == null) {
firstButton = new JButton();
firstButton.setText("首页");
firstButton.setBounds(new Rectangle(0, 1, 60, 24));
firstButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
numberOfPage = 1;
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return firstButton;
}
/**
* This method initializes preButton
*
* @return javax.swing.JButton
*/
private JButton getPreButton() {
if (preButton == null) {
preButton = new JButton();
preButton.setText("上一页");
preButton.setBounds(new Rectangle(60, 1, 75, 24));
preButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
if (numberOfPage <= totalPage && numberOfPage > 1) {
numberOfPage = numberOfPage - 1;
}
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return preButton;
}
/**
* This method initializes nextButton
*
* @return javax.swing.JButton
*/
private JButton getNextButton() {
if (nextButton == null) {
nextButton = new JButton();
nextButton.setText("下一页");
nextButton.setBounds(new Rectangle(135, 1, 75, 24));
nextButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
if (numberOfPage < totalPage) {
numberOfPage = numberOfPage + 1;
}
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return nextButton;
}
/**
* This method initializes lastButton
*
* @return javax.swing.JButton
*/
private JButton getLastButton() {
if (lastButton == null) {
lastButton = new JButton();
lastButton.setText("尾页");
lastButton.setBounds(new Rectangle(210, 1, 60, 24));
lastButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
numberOfPage = totalPage;
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return lastButton;
}
public void setDataOfTable(JTable jTable) {
getModel().setData(tableData);
jTable.updateUI();
page = "共 " + totalPage + " 页 当前第 " + numberOfPage + " 页";
jLabel.setText(page);
if (numberOfPage == 1) {
firstButton.setEnabled(false);
preButton.setEnabled(false);
nextButton.setEnabled(true);
lastButton.setEnabled(true);
} else if (numberOfPage == totalPage) {
firstButton.setEnabled(true);
preButton.setEnabled(true);
nextButton.setEnabled(false);
lastButton.setEnabled(false);
} else {
firstButton.setEnabled(true);
preButton.setEnabled(true);
nextButton.setEnabled(true);
lastButton.setEnabled(true);
}
}
public PageButtonTableModel getModel() {
return model;
}
public void setModel(PageButtonTableModel model) {
this.model = model;
}
}
1 新建接口
import java.util.List;
public interface PageInterface {
/**
* 根据页数,每页显示行数返回jtable显示信息
* @param page
* @param rows
* @return
*/
public List getTableList(int page, int rows);
}
2 根据路径查找类
public class PageFactory {
/**
* 根据路径查找类
* @param className 路径
* @return
* @throws InstantiationException
* @throws IllegalAccessException
*/
public static PageInterface getClass(String className)
throws InstantiationException, IllegalAccessException {
PageInterface production = null;
try {
production = (PageInterface) Class.forName (className).newInstance();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return production;
}
}
3 根据路径,页数,每页显示行数得到jtable显示的信息
public class PageList {
public List showListOfTable(String a, int page, int rows)
throws InstantiationException, IllegalAccessException {
PageInterface cat = PageFactory.getClass(a);
List list = cat.getTableList(page, rows);
return list;
}
}
4 建立一个model
public class PageButtonTableModel extends DefaultTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
String header[];
List<Object[]> data = new ArrayList<Object[]>();
public PageButtonTableModel() {
}
public List<Object[]> getData() {
return data;
}
public void setData(List<Object[]> data) {
this.data = data;
}
public int getColumnCount() {
return header.length;
}
public String getColumnName(int c) {
return header[c];
}
public Object getValueAt(int row, int column) {
return data.get(row)[column];
}
public boolean isCellEditable(int r, int c) {
return false;
}
public int getRowCount() {
if (data != null) {
return data.size();
} else {
return 0;
}
}
}
5 建立共用模板
public class ButtonPanel extends JPanel {
private static final long serialVersionUID = 1L;
private JButton firstButton = null;
private JButton preButton = null;
private JButton nextButton = null;
private JButton lastButton = null;
private JLabel jLabel = null;
// ====================
private String page;
private List<Object[]> tableData;
private PageButtonTableModel model;
private int totalPage;
private int numberOfPage = 1;
private String className;
private PageList pList = new PageList(); // @jve:decl-index=0:
private int rows;
private JTable jTable;
/**
*
* @param totalPage 总页数
* @param className 类名
* @param rows 每页显示行数
* @param jTable
*/
public ButtonPanel(int totalPage, String className,
int rows, JTable jTable) {
super();
this.totalPage = totalPage;
this.className = className;
this.rows = rows;
this.jTable = jTable;
page = "共 " + totalPage + " 页 当前第 " + numberOfPage + " 页";
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(270, 1, 129, 24));
jLabel.setText(page);
this.setSize(400, 26);
this.setLayout(null);
this.add(getFirstButton(), null);
this.add(getPreButton(), null);
this.add(getNextButton(), null);
this.add(getLastButton(), null);
this.add(jLabel, null);
}
/**
* This method initializes firstButton
*
* @return javax.swing.JButton
*/
private JButton getFirstButton() {
if (firstButton == null) {
firstButton = new JButton();
firstButton.setText("首页");
firstButton.setBounds(new Rectangle(0, 1, 60, 24));
firstButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
numberOfPage = 1;
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return firstButton;
}
/**
* This method initializes preButton
*
* @return javax.swing.JButton
*/
private JButton getPreButton() {
if (preButton == null) {
preButton = new JButton();
preButton.setText("上一页");
preButton.setBounds(new Rectangle(60, 1, 75, 24));
preButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
if (numberOfPage <= totalPage && numberOfPage > 1) {
numberOfPage = numberOfPage - 1;
}
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return preButton;
}
/**
* This method initializes nextButton
*
* @return javax.swing.JButton
*/
private JButton getNextButton() {
if (nextButton == null) {
nextButton = new JButton();
nextButton.setText("下一页");
nextButton.setBounds(new Rectangle(135, 1, 75, 24));
nextButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
if (numberOfPage < totalPage) {
numberOfPage = numberOfPage + 1;
}
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return nextButton;
}
/**
* This method initializes lastButton
*
* @return javax.swing.JButton
*/
private JButton getLastButton() {
if (lastButton == null) {
lastButton = new JButton();
lastButton.setText("尾页");
lastButton.setBounds(new Rectangle(210, 1, 60, 24));
lastButton.addActionListener(new java.awt.event.ActionListener() {
@SuppressWarnings("unchecked")
public void actionPerformed(java.awt.event.ActionEvent e) {
numberOfPage = totalPage;
try {
tableData = pList.showListOfTable(className,
numberOfPage, rows);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
setDataOfTable(jTable);
}
});
}
return lastButton;
}
public void setDataOfTable(JTable jTable) {
getModel().setData(tableData);
jTable.updateUI();
page = "共 " + totalPage + " 页 当前第 " + numberOfPage + " 页";
jLabel.setText(page);
if (numberOfPage == 1) {
firstButton.setEnabled(false);
preButton.setEnabled(false);
nextButton.setEnabled(true);
lastButton.setEnabled(true);
} else if (numberOfPage == totalPage) {
firstButton.setEnabled(true);
preButton.setEnabled(true);
nextButton.setEnabled(false);
lastButton.setEnabled(false);
} else {
firstButton.setEnabled(true);
preButton.setEnabled(true);
nextButton.setEnabled(true);
lastButton.setEnabled(true);
}
}
public PageButtonTableModel getModel() {
return model;
}
public void setModel(PageButtonTableModel model) {
this.model = model;
}
}
评论
6 楼
ytsmtxxi
2010-05-04
太复杂了。
5 楼
fisherhe
2010-05-04
有点复杂了撒。
4 楼
xiangdefei
2010-05-04
LZ,你的分页也写得太复杂了点吧。。
3 楼
kaki
2010-05-04
好复杂啊!!!
2 楼
yqklw521
2010-04-29
后台ejb的写法如下:
public class AppatatusPageTest implements ApparatusPageTestRemote {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<Apparatus> queryApparatus(int whichPage, int pagesize) {
// TODO Auto-generated method stub
try {
String sql = "select a from Apparatus a";
Query query = entityManager.createQuery(sql);
// 从结果集中的那个索引开始获取
if(whichPage>=1){
query.setFirstResult((whichPage - 1) * pagesize);
}
// 设置获取多少条记录
query.setMaxResults(pagesize);
List<Apparatus> list = query.getResultList();
//分离内存中受EntityManager管理的实体bean,让VM进行垃圾回收
entityManager.clear();
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public Integer querySumApparatus() {
String sql = "select count(*) from Apparatus a";
Query query = entityManager.createQuery(sql);
int totalPageSize = Integer.valueOf(query.getResultList().get(0)
.toString());
return totalPageSize;
}
}
public class AppatatusPageTest implements ApparatusPageTestRemote {
@PersistenceContext
private EntityManager entityManager;
@Override
public List<Apparatus> queryApparatus(int whichPage, int pagesize) {
// TODO Auto-generated method stub
try {
String sql = "select a from Apparatus a";
Query query = entityManager.createQuery(sql);
// 从结果集中的那个索引开始获取
if(whichPage>=1){
query.setFirstResult((whichPage - 1) * pagesize);
}
// 设置获取多少条记录
query.setMaxResults(pagesize);
List<Apparatus> list = query.getResultList();
//分离内存中受EntityManager管理的实体bean,让VM进行垃圾回收
entityManager.clear();
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public Integer querySumApparatus() {
String sql = "select count(*) from Apparatus a";
Query query = entityManager.createQuery(sql);
int totalPageSize = Integer.valueOf(query.getResultList().get(0)
.toString());
return totalPageSize;
}
}
1 楼
yqklw521
2010-04-29
现在进入测试
1 建立table的model
public class PageModel2 extends PageButtonTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
String header[] = { "姓名", "地址", "年龄", "性别", "电话" };
List<Object[]> data = new ArrayList<Object[]>();
public PageModel2() {
super();
}
public List<Object[]> getData() {
return data;
}
public void setData(List<Object[]> data) {
this.data = data;
}
public int getColumnCount() {
return header.length;
}
public String getColumnName(int c) {
return header[c];
}
public Object getValueAt(int row, int column) {
return data.get(row)[column];
}
public boolean isCellEditable(int r, int c) {
return false;
}
public int getRowCount() {
if (data != null) {
return data.size();
} else {
return 0;
}
}
}
2 建立bean
public class PageTableBean {
String name;
String address;
int age;
String sex;
String photo;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
}
3 建立测试页
public class PageFrame2 extends JFrame implements PageInterface{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
List listData; // @jve:decl-index=0:
String className = "aPage.PageFrame2"; // @jve:decl-index=0:
private PageModel2 model;
private List<Object[]> tableData; // @jve:decl-index=0:
private int totalPage = 20;
private JPanel jPanel = null;
int rows = 20;
/**
* This is the default constructor
*/
public PageFrame2() {
super();
tableData = this.getTableList(1, rows);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(700, 600);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(28, 13, 604, 224));
jScrollPane.setViewportView(getJTable());
jScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
model = new PageModel2();
jTable = new JTable();
model.setData(tableData);
jTable.setModel(model);
}
return jTable;
}
public List getTableList(int page, int rows) {
List list = getList(page, rows);
listData = new ArrayList();
if (list.size() > 0 && list != null) {
for (Object bean : list) {
if (bean instanceof PageTableBean) {
PageTableBean pageBean = (PageTableBean) bean;
String name = "";
if (pageBean.getName() != null) {
name = pageBean.getName();
}
String address = "";
if (pageBean.getAddress() != null) {
address = pageBean.getAddress();
}
int age = 0;
if (pageBean.getAge() != 0) {
age = pageBean.getAge();
}
String sex = "";
if (pageBean.getSex() != null) {
sex = pageBean.getSex();
}
String photo = "";
if (pageBean.getPhoto() != null) {
photo = pageBean.getPhoto();
}
Object[] ob = new Object[5];
ob[0] = name;
ob[1] = address;
ob[2] = age;
ob[3] = sex;
ob[4] = photo;
listData.add(ob);
}
}
}
return listData;
}
public static List<PageTableBean> getList(int page, int rows) {
List<PageTableBean> list = new ArrayList<PageTableBean>();
for (int i = page; i < rows + page; i++) {
PageTableBean bean = new PageTableBean();
bean.setName("name" + i);
bean.setAddress("address" + i);
bean.setAge(i);
if (i % 2 == 0) {
bean.setSex("男");
} else {
bean.setSex("女");
}
bean.setPhoto("photo" + i);
list.add(bean);
}
return list;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(27, 237, 605, 30));
ButtonPanel bp = new ButtonPanel(totalPage, className, rows,
jTable);
bp.setBounds(new Rectangle(100, 0, 400, 30));
bp.setModel(model);
jPanel.add(bp);
}
return jPanel;
}
}
运行ok
1 建立table的model
public class PageModel2 extends PageButtonTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
String header[] = { "姓名", "地址", "年龄", "性别", "电话" };
List<Object[]> data = new ArrayList<Object[]>();
public PageModel2() {
super();
}
public List<Object[]> getData() {
return data;
}
public void setData(List<Object[]> data) {
this.data = data;
}
public int getColumnCount() {
return header.length;
}
public String getColumnName(int c) {
return header[c];
}
public Object getValueAt(int row, int column) {
return data.get(row)[column];
}
public boolean isCellEditable(int r, int c) {
return false;
}
public int getRowCount() {
if (data != null) {
return data.size();
} else {
return 0;
}
}
}
2 建立bean
public class PageTableBean {
String name;
String address;
int age;
String sex;
String photo;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getPhoto() {
return photo;
}
public void setPhoto(String photo) {
this.photo = photo;
}
}
3 建立测试页
public class PageFrame2 extends JFrame implements PageInterface{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JTable jTable = null;
List listData; // @jve:decl-index=0:
String className = "aPage.PageFrame2"; // @jve:decl-index=0:
private PageModel2 model;
private List<Object[]> tableData; // @jve:decl-index=0:
private int totalPage = 20;
private JPanel jPanel = null;
int rows = 20;
/**
* This is the default constructor
*/
public PageFrame2() {
super();
tableData = this.getTableList(1, rows);
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(700, 600);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(getJPanel(), null);
}
return jContentPane;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(28, 13, 604, 224));
jScrollPane.setViewportView(getJTable());
jScrollPane
.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
}
return jScrollPane;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
private JTable getJTable() {
if (jTable == null) {
model = new PageModel2();
jTable = new JTable();
model.setData(tableData);
jTable.setModel(model);
}
return jTable;
}
public List getTableList(int page, int rows) {
List list = getList(page, rows);
listData = new ArrayList();
if (list.size() > 0 && list != null) {
for (Object bean : list) {
if (bean instanceof PageTableBean) {
PageTableBean pageBean = (PageTableBean) bean;
String name = "";
if (pageBean.getName() != null) {
name = pageBean.getName();
}
String address = "";
if (pageBean.getAddress() != null) {
address = pageBean.getAddress();
}
int age = 0;
if (pageBean.getAge() != 0) {
age = pageBean.getAge();
}
String sex = "";
if (pageBean.getSex() != null) {
sex = pageBean.getSex();
}
String photo = "";
if (pageBean.getPhoto() != null) {
photo = pageBean.getPhoto();
}
Object[] ob = new Object[5];
ob[0] = name;
ob[1] = address;
ob[2] = age;
ob[3] = sex;
ob[4] = photo;
listData.add(ob);
}
}
}
return listData;
}
public static List<PageTableBean> getList(int page, int rows) {
List<PageTableBean> list = new ArrayList<PageTableBean>();
for (int i = page; i < rows + page; i++) {
PageTableBean bean = new PageTableBean();
bean.setName("name" + i);
bean.setAddress("address" + i);
bean.setAge(i);
if (i % 2 == 0) {
bean.setSex("男");
} else {
bean.setSex("女");
}
bean.setPhoto("photo" + i);
list.add(bean);
}
return list;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(null);
jPanel.setBounds(new Rectangle(27, 237, 605, 30));
ButtonPanel bp = new ButtonPanel(totalPage, className, rows,
jTable);
bp.setBounds(new Rectangle(100, 0, 400, 30));
bp.setModel(model);
jPanel.add(bp);
}
return jPanel;
}
}
运行ok
相关推荐
分页封装类
自己写的一个js分页控件.已经封装,可以直接使用. 适合各种用途的分页控制. 如果界面不够美观,只需要修改css即可.
本项目提供了一个针对SQL Server数据库的Java代码封装,帮助开发者快速实现分页功能,避免重复编写类似的代码。 首先,我们需要理解分页的基本原理。在SQL中,我们可以使用`LIMIT`(在MySQL中)或`OFFSET`和`FETCH ...
在这个文档中,我们将探讨如何使用`MyFaces`结合`Oracle`进行大数据表的分页封装。 首先,我们来看`DataPage`类。这个类是用于存储和管理分页数据的核心,它包含了三个主要属性:`datasetSize`(数据集总大小),`...
描述中的"分页封装"进一步确认了这个内容的核心是关于如何有效地实现和组织分页代码。 分页的基本原理是将大量数据分成若干个较小的部分,每次只加载一部分到用户界面,而不是一次性加载所有数据。这样可以减少内存...
"php封装的page分页类" 是一个专门用于处理这种需求的类库,它简化了PHP分页的实现过程,通过封装核心逻辑,使开发者能够快速、高效地实现分页功能。 首先,我们要理解分页的基本原理。在数据库查询中,如果一次性...
2. **生成分页链接** 分页链接应包含当前页码,以便用户点击后能跳转到正确的页面。可以使用PHP的`$_GET`数组来传递页码,创建一个HTML链接: ```php for ($i = 1; $i $totalPages; $i++) { echo '$i . '">' . $...
java swing表格分页控件封装,有利于在开发中节约时间
HibernateUtil 分页 增删改查 封装 HibernateUtil 分页 增删改查 封装 HibernateUtil 分页 增删改查 封装
在Vue2框架中,ElementUI是一个非常流行的UI组件库,提供了丰富的组件,如表格、按钮、弹窗等,其中el-pagination是用于实现分页功能的组件。为了在多个页面上复用并统一分页样式,我们可以将其封装为一个公用组件。...
综上所述,Spring JdbcTemplate结合MySQL的分页查询封装涉及到的主要知识点有:Spring的JdbcTemplate用法、MySQL的分页查询(LIMIT和OFFSET)、结果集映射、分页结果对象的构建、以及代码封装与复用。通过这些技术,...
本文将深入探讨如何在Java中实现Web分页封装,以便在实际项目中灵活应用。 首先,我们需要了解分页的基本概念。分页是将大量数据分割成较小、可管理的部分,每次只加载一部分到前端显示。这有助于减少网络传输的...
本项目是针对这一需求,封装了一个服务器端的分页控件,旨在简化开发流程,减少不必要的序列化代码,并提供更灵活的分页展示方式。 首先,我们要理解分页的基本原理。在服务器端,分页通常涉及到从数据库中获取特定...
2. Hibernate分页封装 在Hibernate中,我们可以使用Criteria API来实现分页。Criteria API是一种基于对象的查询语言,可以用来执行SELECT、INSERT、UPDATE和DELETE操作。下面是一个简单的Hibernate分页封装的示例...
总的来说,使用JavaScript实现异步分页封装,不仅可以提升用户体验,还能使代码结构清晰,易于维护。通过封装组件,可以方便地在多个地方复用这一功能,大大提高了开发效率。在实际项目中,结合前端框架如React、Vue...
以"28_传智播客巴巴运动网_将Web层分页封装成通用模块"为例,该示例可能演示了如何在Web应用中实现分页功能的通用封装。可能涉及到的技术栈包括但不限于Spring MVC、MyBatis等。开发者通过创建一个分页工具类,实现...
跟我上面的java底层简易封装配套的。有需要的也可以学习下。
本资源提供了一种高效且简洁的分页解决方案,利用.tag标签技术来封装分页逻辑,使得在JSP页面中的实现变得简单易懂。 首先,我们来详细了解一下`.tag`标签。`.tag`文件是JSP标准标签库(JSTL)的一部分,用于创建...
这里提到的是一个由个人开发者封装的简单分页插件,它可以帮助我们轻松地在网页上实现数据的分页显示。 分页的基本原理是将大数据集分割成较小、可管理的部分,通常每一页显示一定数量的条目。这样可以提高用户体验...
本教程将深入探讨如何使用ADO.NET进行分页封装,特别是对于涉及多表连接查询的场景。分页在大数据量的展示中尤为重要,因为它允许用户以更高效的方式浏览和管理数据,而不会一次性加载所有记录导致性能下降。 首先...