SSH:分页实现

StudentAction:

public class StudentAction extends ActionSupport {


	// 初始化下拉列表
	@Resource
	private StudentService studentService;

....
....
set/get

StudentService:

public class StudentService {
	@Resource
	private StudentDAO studentDAO;

	public List<Student> findByPager(Pager pager) {
		return studentDAO.findByPage(pager);
	}


StudentDao

@Transactional
public class StudentDAO {
        public List<Student> findByPage(Pager pager) {
		Query queryObject = getCurrentSession().createQuery("from Student");
		// 设置查询的起始行和查询条目数量
		queryObject.setFirstResult(pager.getStartRow());
		queryObject.setMaxResults(pager.getRows());
		return queryObject.list();
	}
Pager:

public class Pager {
	private int totalRows = 100; // 总行数
	private int rows = 10; // 每页显示的行数
	private int page = 1; // 当前页号,从1开始
	private int totalPage = 5; // 总页数
	private int startRow = 0; // 当前页在数据库中的起始行

	public Pager() {
	}
...
set/get



原文地址:https://www.cnblogs.com/jasonhaven/p/7355025.html