一、首先画图说下Oracle分页原理
Oracle有个rownum列,大家试着查询看下,我们就利用这列实现分页,如下 :
select * from (
select t.* , rownum rn from goods t where rownum <=6 )
)
where rn >=4
把上述的数字使用变量替换掉即可
二、搭建struts和hibernate框架
1、总体框架如下图
2、配置文件
(1)struts.xml
<session-factory>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="connection.url">
jdbc:oracle:thin:127.0.0.1:1521:orcl
</property>
<property name="connection.username">lily</property>
<property name="connection.password">m123</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="myeclipse.connection.profile">
oracle.jdbc.driver.OracleDriver
</property>
<mapping resource="com/po/Goods.hbm.xml" />
</session-factory>
3、工具类
HibernateSessionFactory.java
package com.test;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
-
Configures and provides access to Hibernate sessions, tied to the
-
current thread of execution. Follows the Thread Local Session
-
pattern, see {@link http://hibernate.org/42.html }.
*/