Java tutorial
/* * The MIT License (MIT) * * Copyright (c) 2014-2017 abel533@gmail.com * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.sinotopia.mybatis.pagehelper.page; import com.sinotopia.mybatis.pagehelper.Page; import com.sinotopia.mybatis.pagehelper.util.StringUtil; import com.sinotopia.mybatis.pagehelper.PageHelper; import com.sinotopia.mybatis.pagehelper.util.PageObjectUtil; import org.apache.ibatis.session.RowBounds; import java.util.Properties; /** * Page ?? * * @author cacotopia */ public class PageParams { //RowBounds?offsetPageNum - ? protected boolean offsetAsPageNum = false; //RowBounds?count - ? protected boolean rowBoundsWithCount = false; //truepagesize0RowBoundslimit=0? protected boolean pageSizeZero = false; //?? protected boolean reasonable = false; //??????false protected boolean supportMethodsArguments = false; //count(0) protected String countColumn = "0"; /** * ?? * * @param parameterObject * @param rowBounds * @return */ public Page getPage(Object parameterObject, RowBounds rowBounds) { Page page = PageHelper.getLocalPage(); if (page == null) { if (rowBounds != RowBounds.DEFAULT) { if (offsetAsPageNum) { page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new Page(new int[] { rowBounds.getOffset(), rowBounds.getLimit() }, rowBoundsWithCount); //offsetAsPageNum=falsePageNum?reasonablefalse page.setReasonable(false); } } else if (supportMethodsArguments) { try { page = PageObjectUtil.getPageFromObject(parameterObject, false); } catch (Exception e) { return null; } } if (page == null) { return null; } PageHelper.setLocalPage(page); } //?? if (page.getReasonable() == null) { page.setReasonable(reasonable); } //truepagesize0RowBoundslimit=0? if (page.getPageSizeZero() == null) { page.setPageSizeZero(pageSizeZero); } return page; } public void setProperties(Properties properties) { //offsetPageNum String offsetAsPageNum = properties.getProperty("offsetAsPageNum"); this.offsetAsPageNum = Boolean.parseBoolean(offsetAsPageNum); //RowBounds???count String rowBoundsWithCount = properties.getProperty("rowBoundsWithCount"); this.rowBoundsWithCount = Boolean.parseBoolean(rowBoundsWithCount); //truepagesize0RowBoundslimit=0? String pageSizeZero = properties.getProperty("pageSizeZero"); this.pageSizeZero = Boolean.parseBoolean(pageSizeZero); //??true?????false?? String reasonable = properties.getProperty("reasonable"); this.reasonable = Boolean.parseBoolean(reasonable); //??????false String supportMethodsArguments = properties.getProperty("supportMethodsArguments"); this.supportMethodsArguments = Boolean.parseBoolean(supportMethodsArguments); //count String countColumn = properties.getProperty("countColumn"); if (StringUtil.isNotEmpty(countColumn)) { this.countColumn = countColumn; } //offsetAsPageNum=false? //? PageObjectUtil.setParams(properties.getProperty("params")); } public boolean isOffsetAsPageNum() { return offsetAsPageNum; } public boolean isRowBoundsWithCount() { return rowBoundsWithCount; } public boolean isPageSizeZero() { return pageSizeZero; } public boolean isReasonable() { return reasonable; } public boolean isSupportMethodsArguments() { return supportMethodsArguments; } public String getCountColumn() { return countColumn; } }