开发采用spring+ibatis,数据库用oracle,数据量有几千万以上,而且还要不断的增多,用了三层子查询实现分页控制
下面都只是举的例子
<sqlMap namespace="Y_wjlx">
<resultMap class="com.ctgusec.model.Y_wjlx" id="y_wjlx">
<result property="wjbh" column="wjbh" />
<result property="wjmc" column="wjmc" />
</resultMap>
<select id="getAllY_wjlx" resultMap="y_wjlx">
<![CDATA[
SELECT wjbh,wjmc FROM (SELECT row_.*, rownum rownum_ FROM (select wjbh,wjmc,rownum rn from y_wjlx) row_ WHERE rownum <= #end#) WHERE rownum_ > #start#
]]>
</select>
</sqlMap>
用了个模型基类存储分页参数,模型类可以继承此类
public class BaseModel {
private Integer start = 0;
private Integer end = 30;
private Integer size = 30;
private Integer currentPage;
private Integer priviousPage;
private Integer nextPage;
public BaseModel() {
}
public BaseModel(Integer currentPage) {
if (currentPage > 0) {
this.currentPage = currentPage;
this.priviousPage = currentPage - 1;
this.nextPage = currentPage + 1;
this.start = priviousPage * size;
this.end = currentPage * size;
}
}
//省略geter、serter方法
}
dao层:
public class SqlY_wjlxDao extends SqlMapClientDaoSupport implements IY_wjlxDao {
public List getAllY_wjlx(Y_wjlx y_wjlx) {
return this.getSqlMapClientTemplate().queryForList("getAllY_wjlx", y_wjlx);
}
}
控制层:spring控制类实现分页
public class Y_wjlxListAllController extends AbstractController {
Integer currentPage ;
//y_wjlx类继承BaseModel类
Y_wjlx y_wjlx;
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String page = request.getParameter("page");
if (page == null || page.equals("head")) {
currentPage=1;
y_wjlx = new Y_wjlx(currentPage);
request.getSession().setAttribute("currentPage", currentPage);
}
if ("privious".equals(page)) {
currentPage = (Integer) request.getSession().getAttribute("currentPage");
if(currentPage>1) currentPage -= 1;
y_wjlx = new Y_wjlx(currentPage);
request.getSession().setAttribute("currentPage", currentPage);
} else if ("next".equals(page)) {
currentPage = (Integer) request.getSession().getAttribute("currentPage");
currentPage += 1;
y_wjlx = new Y_wjlx(currentPage);
request.getSession().setAttribute("currentPage", currentPage);
}
List list = this.drv_Manager.getAllY_wjlx(y_wjlx);
return new ModelAndView("y_wjlxList", "list", list);
}
private IDrv_Manager drv_Manager;
public void setDrv_Manager(IDrv_Manager drv_Manager) {
this.drv_Manager = drv_Manager;
}
}
jsp页面分页调用
<button onclick="location.href = 'y_wjlxList.shtml?page=head'">首&&页</button>
&&
<button onclick="location.href = 'y_wjlxList.shtml?page=privious'">上一页</button>
&&
<button onclick="location.href='y_wjlxList.shtml?page=next'">下一页</button>
实现了分页,而且前面的数据查询翻页效率很高,但是越到后面越慢(这个好象是没有办法的)
现在的问题是:
1、spring控制类太累赘,好象做了它不该做的事情,翻页控制有没有比较好的办法抽到服务层?
2、翻页也只有:首页、上页、下页;想把最后一页也弄出来,但是担心效率太低,首先要统计数据总数,还有就是三层子查询到了几千万数据后效率就慢了。
有没有比较好的解决办法?