Java请求参数类QueryParameter

时间:2023-03-09 18:34:41
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;
}
}