zoukankan      html  css  js  c++  java
  • Java请求参数类QueryParameter

    import java.util.HashMap;
    import java.util.Map;
    import org.apache.commons.lang.StringUtils;
    
    /**
     * 请求参数类
     * 
     */
    public class QueryParameter {
        public static final String ASC = "asc";
        public static final String DESC = "desc";
        protected int pageNo = 1;
        protected int pageSize = 1;
        protected String orderBy = null;
        protected String order = "asc";
        protected boolean autoCount = false;
        protected Map<String, String> alias = new HashMap<String, String>();
    
        public int getPageSize() {
            return this.pageSize;
        }
    
        public void setPageSize(int pageSize) {
            if (pageSize < 1) {
                pageSize = 1;
            }
            this.pageSize = pageSize;
        }
    
        public boolean isPageSizeSetted() {
            return (this.pageSize > -1);
        }
    
        public int getPageNo() {
            return this.pageNo;
        }
    
        public void setPageNo(int pageNo) {
            if(pageNo < 1){
                pageNo = 1;
            }
        
            this.pageNo = pageNo;
        }
    
        public int getFirst() {
            if ((this.pageNo < 1) || (this.pageSize < 1)){
                return 1;
            }
            return ((this.pageNo - 1) * this.pageSize) + 1;
        }
    
        public boolean isFirstSetted() {
            return ((this.pageNo > 0) && (this.pageSize > 0));
        }
    
        public String getOrderBy() {
            return this.orderBy;
        }
    
        public void setOrderBy(String orderBy) {
            this.orderBy = orderBy;
        }
    
        public boolean isOrderBySetted() {
            return StringUtils.isNotBlank(this.orderBy);
        }
    
        public String getOrder() {
            return this.order;
        }
    
        public void setOrder(String order) {
            order = StringUtils.lowerCase(order);
            String[] orders = StringUtils.split(order, ',');
            for (String orderStr : orders) {
                if (!StringUtils.equals(DESC, orderStr) && !StringUtils.equals(ASC, orderStr))
                    throw new IllegalArgumentException("排序方向" + orderStr + "不是合法值");
            }
            this.order = order.trim();
        }
    
        public boolean isAutoCount() {
            return this.autoCount;
        }
    
        public void setAutoCount(boolean autoCount) {
            this.autoCount = autoCount;
        }
    
        public void addAlias(String name, String alias) {
            this.alias.put(name, alias);
        }
    
        public boolean hasAlias() {
            return (!(this.alias.isEmpty()));
        }
    
        public Map<String, String> getAlias() {
            return this.alias;
        }
    }
  • 相关阅读:
    POJ 1797 Heavy Transportation
    POJ 2253 Frogger
    POJ 2387 Til the Cows Come Home
    HDU 1233 还是畅通工程
    POJ 1287 Networking
    标准C程序设计七---63
    标准C程序设计七---62
    标准C程序设计七---61
    标准C程序设计七---60
    标准C程序设计七---57
  • 原文地址:https://www.cnblogs.com/rubekid/p/4803526.html
Copyright © 2011-2022 走看看