oracle数据库分页到前端页面显示

时间:2021-02-22 21:10:55

前端代码:
(class=”pagination”是bootstrap3.x框架中的样式)

      <ul class="pagination">
<li><a href="getNotFinishedWt1?tab=finished&pageNo1=1"
style="text-decoration: none">
首页</a> </li>
<li><a href="getNotFinishedWt1?tab=finished&pageNo1=${pageModel1.prePage}"
style="text-decoration: none">
上一页</a></li>
<li><a href="getNotFinishedWt1?tab=finished&pageNo1=${pageModel1.nextPage}"
style="text-decoration: none">
下一页</a></li>
<li><a href="getNotFinishedWt1?tab=finished&pageNo1=${pageModel1.lastPage }"
style="text-decoration: none">
尾页</a></li>
<li><span>共${pageModel1.pageNo}/${pageModel1.totalPage}页</span></li>
</ul>

后台代码:

    @RequestMapping("/getNotFinishedWt1")
public ModelAndView getNotFinishedWt1(Integer pageNo, HttpServletRequest request, Integer pageNo1) {
User user = this.getSessionUser(request);
ModelAndView mav = new ModelAndView("jsonView");
int pageSize = 3;//每页显示几条数据
if (null == pageNo) {
pageNo = 1;
}
PageModel<CXGJ> pageModel = null;
pageModel = cxgjService.getNotFinishedWt1(pageNo, pageSize, user);
mav.addObject("pageModel", pageModel);
mav.setViewName("/new/zyjs/cxgj-zyfzr");
return mav;
}
    public PageModel<CXGJ> getNotFinishedWt1(int pageNo, int pageSize, User user) throws zyrzException {
PageModel<CXGJ> pageModel = new PageModel<>();
Map<String, Object> map = new HashMap<>();
map.put("pageNo", pageNo);
map.put("pageSize", pageSize);
map.put("wtfzr", user.getUserName());
pageModel.setPageNo(pageNo);
pageModel.setPageSize(pageSize);
try {
pageModel.setCnt(cxgjDao.getNotFinishedWtCnt1(map));
pageModel.setDataList(cxgjDao.getNotFinishedWt1(map));
} catch (SQLException e) {
log.error("查询数据库异常", e);
throw new zyrzException("查询数据库异常");
}
return pageModel;
}
    public int getNotFinishedWtCnt1(Map<String, Object> map) throws SQLException {
String sql = "select count(1) from zyrz_cxgj where (status=1 and WTFZR is null) or (WTFZR='" + map.get("wtfzr").toString() + "' and status=2 )";
return this.jdbcTemplate.queryForInt(sql);
}
    public List<Map<String, Object>> getNotFinishedWt1(Map<String, Object> map) throws SQLException {
String sql = "select CXGJ_ID,WTSM,WTTCR,WTTCSJ,YQJJSJ,JJCS,SJJJSJ,STATUS from(" +
" select ROWNUM as rn,CXGJ_ID,WTSM,WTTCR,WTTCSJ,YQJJSJ,JJCS,SJJJSJ,STATUS from( " +
"select CXGJ_ID,WTSM,WTTCR,WTTCSJ,YQJJSJ,JJCS,SJJJSJ,STATUS from zyrz_cxgj " +
" where (status=1 and WTFZR is null) or (WTFZR='" + map.get("wtfzr").toString() + "' and status=2 ) order by STATUS DESC ) c1) c2 " +
"where c2.rn>'" + Integer.parseInt(map.get("pageSize").toString()) * (Integer.parseInt(map.get("pageNo").toString()) - 1) + "'" +
" and c2.rn <='" + Integer.parseInt(map.get("pageSize").toString()) * Integer.parseInt(map.get("pageNo").toString()) + "'";
return this.jdbcTemplate.queryForList(sql);
}

分页模型的类

package com.rsp.global.util;

import java.util.List;
import java.util.Map;

/**
* 分页模型
* PageModel <T> T:指的是dataList返回的数据类型
* T的类型由使用时动态指定,如果指定为Dept,List<Dept> dataList
*
* @author Administrator
*/

public class PageModel<T> {
/**
* 每页显示的数量
*/

private int pageSize;

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

/**
* 当前页码
*/

private int pageNo;

public int getPageNo() {
return pageNo;
}

public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}

/**
* 分页数据
*/

private List<Map<String, Object>> dataList;

public List<Map<String, Object>> getDataList() {
return dataList;
}

public void setDataList(List<Map<String, Object>> dataList) {
this.dataList = dataList;
}

/**
* 分页表*有多少条数据
*/

private int cnt;

public int getCnt() {
return cnt;
}

public void setCnt(int cnt) {
this.cnt = cnt;
}


/**
* 获取首页页码
*/

public int getFirstPage() {
return 1;
}

/**
* 获取上一页页码
*/

public int getPrePage() {
if (this.pageNo == 1) {
return 1;
} else {
return this.pageNo - 1;
}
}

/**
* 获取下一页
*/

public int getNextPage() {
if (this.pageNo == getLastPage()) {
return this.getLastPage();

} else {
return this.pageNo + 1;
}

}

/**
* 获取最后一页
*/

public int getLastPage() {
return this.getTotalPage();
}

/**
* 获取总页数
*
* @return
*/

public int getTotalPage() {
return (this.cnt % this.pageSize == 0 ? this.cnt / this.pageSize : this.cnt / this.pageSize + 1);
}

}

自定义异常工具类

package com.rsp.global.exception;


public class zyrzException extends RuntimeException {

private static final long serialVersionUID = 1L;

private String errorCode;

private String msg;

public zyrzException() {
// TODO Auto-generated constructor stub
}

public zyrzException(String errorCode, String msg) {
super();
this.errorCode = errorCode;
this.msg = msg;
}

public String getErrorCode() {
return errorCode;
}

public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public zyrzException(String msg) {
super(msg);
}
}