码迷,mamicode.com
首页 > 编程语言 > 详细

Java请求参数类QueryParameter

时间:2015-09-12 21:40:34      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

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;
    }
}

 

Java请求参数类QueryParameter

标签:

原文地址:http://www.cnblogs.com/rubekid/p/4803526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!