package com.xxx.xxx.util;
import java.io.Serializable;
import java.util.List;
public class Page<T> implements Serializable {
private static final long serialVersionUID = -3640039664184539350L;
private long page;
private long prePage;
private long nextPage;
private long pageSize;
private long totalCount;
private long pageCount;
private long sqlFriParm;
private long sqlEndParm;
private long beginPageIndex;
private long endPageIndex;
private List<T> rows;
/**
* @return the page
*/
public long getPage() {
return page;
}
/**
* @param page the page to set
*/
public void setPage(long page) {
this.page = page;
}
/**
* @return the prePage
*/
public long getPrePage() {
return prePage;
}
/**
* @param prePage the prePage to set
*/
public void setPrePage(long prePage) {
this.prePage = prePage;
}
/**
* @return the nextPage
*/
public long getNextPage() {
if(nextPage<=0){
return 1;
}else{
return nextPage>pageCount?pageCount:nextPage;
}
}
/**
* @param nextPage the nextPage to set
*/
public void setNextPage(long nextPage) {
this.nextPage = nextPage;
}
/**
* @return the pageSize
*/
public long getPageSize() {
return pageSize;
}
/**
* @param pageSize the pageSize to set
*/
public void setPageSize(long pageSize) {
this.pageSize = pageSize<=0?10:pageSize;
}
/**
* @return the totalCount
*/
public long getTotalCount() {
return totalCount;
}
/**
* @param totalCount the totalCount to set
*/
public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
}
/**
* @return the pageCount
*/
public long getPageCount() {
return pageCount;
}
/**
* @param pageCount the pageCount to set
*/
public void setPageCount(long pageCount) {
this.pageCount = pageCount;
}
/**
* @return the rows
*/
public List<T> getRows() {
return rows;
}
/**
* @param rows the rows to set
*/
public void setRows(List<T> rows) {
this.rows = rows;
}
public void resetNextPage(){
nextPage=page+1;
this.prePage = page -1>0?page-1:1;
pageCount=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
if(pageCount <= 10){
beginPageIndex = 1;
endPageIndex = pageCount;
}else {
beginPageIndex = page -4;
endPageIndex = page + 5;
if (beginPageIndex < 1){
beginPageIndex = 1;
endPageIndex = 10;
}
if (endPageIndex > pageCount){
endPageIndex = pageCount;
beginPageIndex = pageCount - 10 + 1;
}
}
}
public Page() {
}
public Page(long page,long pageSize ){
this.pageSize = pageSize;
this.page = page;
this.sqlFriParm = (page - 1) * pageSize + 1;
this.sqlEndParm = sqlFriParm + pageSize - 1;
}
public long getSqlEndParm() {
return sqlEndParm;
}
public void setSqlEndParm(long sqlEndParm) {
this.sqlEndParm = sqlEndParm;
}
public long getSqlFriParm() {
return sqlFriParm;
}
public void setSqlFriParm(long sqlFriParm) {
this.sqlFriParm = sqlFriParm;
}
public long getBeginPageIndex() {
return beginPageIndex;
}
public void setBeginPageIndex(long beginPageIndex) {
this.beginPageIndex = beginPageIndex;
}
public long getEndPageIndex() {
return endPageIndex;
}
public void setEndPageIndex(long endPageIndex) {
this.endPageIndex = endPageIndex;
}
@Override
public String toString() {
return "Page{" +
"page=" + page +
", prePage=" + prePage +
", nextPage=" + nextPage +
", pageSize=" + pageSize +
", totalCount=" + totalCount +
", pageCount=" + pageCount +
", sqlFriParm=" + sqlFriParm +
", beginPageIndex=" + beginPageIndex +
", endPageIndex=" + endPageIndex +
", rows=" + rows +
'}';
}
}
@ApiOperation(value = "#2--whatever",notes = "")
@PostMapping("/querydata")
public Result QueryDimensionTabData(@RequestParam String tableName,@RequestParam Integer currentPage, @RequestParam Integer pageSize){
logger.info("start ShowDataController.QueryDimensionTabData()...tableName = {},currentPage = {}, pageSize = {}",tableName,currentPage,pageSize);
long start = System.currentTimeMillis();
try {
Page<Map<String, Object>> page = new Page<Map<String, Object>>(currentPage,pageSize);
page = showDataService.QueryDimensionData(page,tableName);
page.resetNextPage();
logger.info("end ShowDataController.QueryDimensionTabData()...cost = {}ms",System.currentTimeMillis() - start);
return ResultGenerator.genSuccessResult(page);
} catch (Exception e) {
logger.error("ShowDataController.QueryDimensionTabData()... Exception = {}",e);
e.printStackTrace();
return ResultGenerator.genServerErrorFailResult();
}
}
@Override
public Page<Map<String, Object>> QueryDimensionData(Page<Map<String, Object>> page, String tableName) {
long totalCount = queryODataMapper.queryTotalCount(tableName.toUpperCase());
page.setTotalCount(totalCount);
List<Map<String, Object>> list = queryODataMapper.QueryDimensionData(page,tableName);
page.setRows(list);
return page;
}
package com.xxx.xxx.oracleMapper
import java.util.List
import java.util.Map
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import com.xxx.xxx.util.Page
@Mapper
public interface QueryDataMapper {
@Select("SELECT * FROM ( SELECT A.*,ROWNUM RN FROM (SELECT * FROM ${tableName} ) A WHERE ROWNUM <= #{page.sqlEndParm}) TL WHERE RN >= #{page.sqlFriParm}")
List<Map<String, Object>> QueryDimensionData(
@Param("page")Page<Map<String, Object>> page,@Param("tableName") String tableName)
@Select("select count(1) from ${tableName}")
long queryTotalCount(@Param("tableName")String tableName)
}