package hsy.util;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
public class PageOperation {
public final static int NUM_PER_PAGE = 10; // 设置每页行数
private JdbcTemplate jt;
public PageOperation() {
super();
}
public PageOperation(JdbcTemplate jt) {
super();
this.jt = jt;
}
public JdbcTemplate getJt() {
return jt;
}
public void setJt(JdbcTemplate jt) {
this.jt = jt;
}
/**
* 求 员工显示 总页数
*/
public int getPricingsTotalPages(int NUM_PER_PAGE) {
int totalRows = jt.queryForInt("select count(*) from emp");
System.out.println("totalRows------->>>>"+totalRows);
// 总行数 % 每页行数 = 0
if (totalRows % NUM_PER_PAGE == 0) {
return totalRows / NUM_PER_PAGE;
} else {
// 总行数 % 每页行数 != 0
return totalRows / NUM_PER_PAGE + 1;
}
}
/**
* 求 员工显示页面 具体页数 ( list 是返回的具体条目 )
*/
public List> getPages(int currentPage, int NUM_PER_PAGE){
List> list= jt.queryForList("select * from emp limit ?,?",
new Object[] { (currentPage * NUM_PER_PAGE - NUM_PER_PAGE), NUM_PER_PAGE });
return list;
}
}