ibatis_ECside数据库分页

JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>

<%@ taglib prefix="ec" uri="http://www.ecside.org"  %>

<%@ page isELIgnored="false"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>test ECtable 数据库分页</title>

<link rel="stylesheet" type="text/css" href="ecside/css/ecside_style.css" />

<script type="text/javascript" src="ecside/js/ecside.js" ></script>

<script type="text/javascript" src="ecside/js/ecside_msg_utf8_cn.js" ></script> 

<script type="text/javascript" src="ecside/js/prototype_mini.js" ></script>

</head>

 

<body>    

<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">

  <tr>

    <td height="100"  style="text-align:center" valign="middle" bgcolor="#f7f7f7">

       <ec:table items="list" var="list" 

retrieveRowsCallback="limit" 

sortRowsCallback="limit" 

filterRowsCallback="limit"

action="XXX.action"

editable="false" 

width="100%" 

listWidth="100%"

classic="true"

doPreload="false"

useAjax="true"

resizeColWidth="false" 

batchUpdate="true"

nearPageNum="0"

toolbarLocation="top"

pageSizeList="10,20,50"

xlsFileName="table1.xls" 

showPrint="true"

filterable="false"

>

<ec:row style="text-align:center">

<ec:column width="5%" property="_0" title="序号"  value="${GLOBALROWCOUNT}" style="text-algin:center" editable="false"/>

<ec:column width="40%" property="userid" title="用户标识" style="text-align:center" editable="false" sortable="true"/>

<ec:column width="40%" property="username" title="用户姓名" style="text-align:center" editable="false" sortable="true"/>

</ec:row>

<c:if test="${msg != null}">

<ec:extendrow>

<tr><td colspan="3" style="text-align:center"><strong><font face='宋体' color='#5b92fa'><c:out value="${msg}"/></font></strong></td></tr>

</ec:extendrow>

</c:if>

</ec:table><br>

</td>

  </tr>

</table>

</body>

<script type="text/javascript">

function myrefresh() 

      ECSideUtil.reload('ec');

      setTimeout('myrefresh()',10000); //指定1秒刷新一次 1000=1秒

setTimeout('myrefresh()',1000); //指定1秒刷新一次 1000=1秒

</script> 

</html>

<!-- 接收已经经过数据库分页处理的List , 必须做设置 retrieveRowsCallback="limit" sortRowsCallback="limit" filterRowsCallback="limit" -->

 

POJO:

 

public class TestVO {

 

private String userid;//用户标识

private String username;//用户姓名

 

//分页用 

private int startRow;

private int endRow;

private String order;

private String sort;

 

 

public int getEndRow() {

return endRow;

}

public void setEndRow(int endRow) {

this.endRow = endRow;

}

public String getOrder() {

return order;

}

public void setOrder(String order) {

this.order = order;

}

public String getSort() {

return sort;

}

public void setSort(String sort) {

this.sort = sort;

}

public int getStartRow() {

return startRow;

}

public void setStartRow(int startRow) {

this.startRow = startRow;

}

 

public String getUserid() {

return userid;

}

public void setUserid(String userid) {

this.userid = userid;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

}

 

ACTION:

 

public class TestAction  extends ActionSupport {

private MailService mailService;

 

public TestService getTestService() {

return testService;

}

 

public void setTestService testService;{

this.testService;= testService;

}

 

public String searchTestList() throws Exception {

HttpServletRequest request = ServletActionContext.getRequest();

TestVO vo=new TestVO();

 

Limit limit = RequestUtils.getLimit(request);

String sort=limit.getSort().getProperty();

String order=limit.getSort().getSortOrder();

int totalRows = RequestUtils.getTotalRowsFromRequest(request);

if (totalRows < 0) {

totalRows = mailService.countGetTestList(vo);

}

 

limit.setRowAttributes(totalRows, 20);

int offset = 0;

int[] rowStartEnd = new int[] { limit.getRowStart() + offset,limit.getRowEnd() + offset };

if (rowStartEnd[1] == 0) {

rowStartEnd[1] = 20;

}

 

vo.setStartRow(rowStartEnd[0]);

vo.setEndRow(rowStartEnd[1]);

vo.setOrder(order);

vo.setSort(sort);

List list = testService.getTestList(vo);

if(!list.isEmpty()){

request.setAttribute("list", list);

}else{

request.setAttribute("msg", "没有符合条件的记录!");

}

return SUCCESS;

}

}

 
 
IBATIS XML:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="test">
<typeAlias alias="test" type="com.ran.pojo.TestVO"/>
<!--获得表信息 --> 
<select id="getTestList" resultClass="test" parameterClass="test">
<![CDATA[
SELECT * FROM (SELECT pagetable.*,ROWNUM AS rowcounter FROM (
SELECT userid,username FROM users where trunc(rksj)=trunc(sysdate)
) pagetable) subt WHERE subt.rowcounter>#startRow#
AND subt.rowcounter<=#endRow#
]]>
</select>
<!--获得表记录数 --> 
<select id="countGetTestList" resultClass="java.lang.String" parameterClass="test">
SELECT count(userid) users where trunc(rksj)=trunc(sysdate)
</select>
</sqlMap>

你可能感兴趣的:(ibatis)