📄 testpage.java
字号:
package edu.neu.sspp.test;
import java.util.Set;
import edu.neu.sspp.PageSeparator;
import edu.neu.sspp.hibernate.HibernateSessionFactory;
import edu.neu.sspp.hibernate.TComment;
import edu.neu.sspp.hibernate.TProject;
import edu.neu.sspp.hibernate.TProjectDAO;
public class TestPage {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestPage tp = new TestPage();
//tp.commentPageTest();
tp.dbPageTest();
}
public void dbPageTest() {
TProjectDAO projectDAO = new TProjectDAO();
TProject project = projectDAO.findById("40288027131a8c8c01131a8c905f0001");
//确实是按顺序排列的,用这种方法得到数组,操作能更灵活一些(效率不如分页查询高)
Set set = project.getTComments();
Object[] comments = set.toArray();
//懒读可以在这里关闭session
HibernateSessionFactory.closeSession();
/*
for(int i = 0; i < comments.length; i++) {
System.out.println(((TComment)comments[i]).getDate());
}
*/
PageSeparator page = new PageSeparator(comments.length, 3);
for(int i = 0; i < page.getTotalPage(); i++) {
for(int j = page.getCurrentPageBegin(); j < page.getCurrentPageEnd(); j++)
System.out.println(((TComment)comments[j]).getContent());
System.out.println();
}
}
public void commentPageTest() {
PageSeparator page = new PageSeparator(103, 5);
System.out.println("Total:" + page.getTotalPage());
System.out.println("Exception:");
try {
page.setCurrentPage(0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Exception:");
try {
page.setCurrentPage(100);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Current Page:" + page.getCurrentPage());
System.out.println(page.getIsBegin());
System.out.println(page.getIsEnd());
System.out.println("Set To Begin!");
page.setToBegin();
System.out.println("Current Page:" + page.getCurrentPage());
System.out.println(page.getIsBegin());
System.out.println(page.getIsEnd());
System.out.println("Set To End!");
page.setToEnd();
System.out.println("Current Page:" + page.getCurrentPage());
System.out.println(page.getIsBegin());
System.out.println(page.getIsEnd());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -