1.sql的编写 ibatis的xml配置文件中
<select id="abatorgenerated_selectByPage" parameterClass="net.zwhd.he.util.paging.Page" resultMap="abatorgenerated_CauserResult">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Mon Mar 18 11:33:43 CST 2013.
-->
SELECT T2.* FROM (SELECT RID FROM (SELECT
R.RID, ROWNUM LINENUM FROM (SELECT ROWID RID FROM CJDB1.CAUSER T ORDER BY
ROWID DESC) R WHERE ROWNUM <= #end#) WHERE LINENUM >= #start#) T1,CJDB1.CAUSER
T2 WHERE T1.RID = T2.ROWID ORDER BY ORDERS DESC
</select>
2.parameterClass="net.zwhd.he.util.paging.Page" 为参数的封装类
package net.zwhd.he.util.paging;
public class Page {
private int start;
private int end;
/**
* @return the start
*/
public int getStart() {
return start;
}
/**
* @param start the start to set
*/
public void setStart(int start) {
this.start = start;
}
/**
* @return the end
*/
public int getEnd() {
return end;
}
/**
* @param end the end to set
*/
public void setEnd(int end) {
this.end = end;
}
public Page(){}
/**
* @param start
* @param end
*/
public Page(int start, int end) {
super();
this.start = start;
this.end = end;
}
}
3.dao层的写法
@Override
public List getListByPage(Map map) {
List<Causer> list = null;
try {
list = this.getSqlMapClient().queryForList("CJDB1_CAUSER.abatorgenerated_selectByPage", map.get("entry"));
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
4.控制层的写法
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String encoding = "UTF-8";
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
ModelAndView mav = new ModelAndView();
// 获取网页分页参数
try {
Map mapss = request.getParameterMap();
String[] strs = new String[] { "selectStatus", "page", "pageSize" };
String[] strsValue = new String[strs.length];
for (int i = 0; i < strs.length; i++) {
String string = strs[i];
if (mapss.containsKey(string)) {
Object[] obj = (Object[]) mapss.get(string);
if (obj.length > 0) {
strsValue[i] = obj[0].toString();
}
}
}
CauserExample example = new CauserExample();
int counts = this.causerService.countByExample(example);
Paging paging = new Paging(counts);
if (mapss.containsKey(strs[0])) {
paging.setPageNumber(Integer.valueOf(strsValue[1]));
paging.setPageSize(Integer.valueOf(strsValue[2]));
}
Page page = new Page(paging.getStartRowNumber(), paging.getEndRowNumber());
// 分页查询数据
Map map = new HashMap();
map.put("entry", page);
List<Causer> list = this.causerService.getListByPage(map);
PagedVo pv = new PagedVo(counts);
pv.setVos(list);
mav.getModel().put("result", pv);
mav.setViewName("ca/list.jsp");
} catch (Exception e) {
e.printStackTrace();
}
return mav;
}