📄 queryobject.java
字号:
package com.easyjf.core.support.query;
import java.util.ArrayList;
import java.util.List;
public class QueryObject implements IQueryObject {
protected Integer pageSize = 10;
protected Integer currentPage = 0;
protected String orderBy;
protected String orderType;
protected List params = new ArrayList();
protected String queryString = "1=1";
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public void setOrderBy(String orderBy) {
this.orderBy = orderBy;
}
public void setOrderType(String orderType) {
this.orderType = orderType;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
protected void setParams(List params) {
this.params = params;
}
public String getOrderType() {
return orderType;
}
public Integer getCurrentPage() {
if (currentPage == null) {
currentPage = -1;
}
return currentPage;
}
public String getOrder() {
return orderType;
}
public String getOrderBy() {
return orderBy;
}
public Integer getPageSize() {
if (pageSize == null) {
pageSize = -1;
}
return pageSize;
}
public PageObject getPageObj() {
PageObject pageObj = new PageObject();
pageObj.setCurrentPage(this.getCurrentPage());
pageObj.setPageSize(this.getPageSize());
if (this.currentPage == null || this.currentPage <= 0) {
pageObj.setCurrentPage(1);
}
return pageObj;
}
public String getQuery() {
customizeQuery();
return queryString + orderString();
}
protected String orderString() {
String orderString = " ";
if (this.getOrderBy() != null && !"".equals(getOrderBy())) {
orderString += " order by obj." + this.getOrderBy();
}
if (this.getOrderType() != null && !"".equals(getOrderType())) {
orderString = orderString + " " + getOrderType();
}
return orderString;
}
public List getParameters() {
return this.params;
}
public IQueryObject addQuery(String field, Object para, String expression) {
if (field != null && para != null) {
queryString += " and " + field + " " + handleExpression(expression)
+ " ? ";
params.add(para);
}
return this;
}
public IQueryObject addQuery(String field, Object para, String expression,
String logic) {
if (field != null && para != null) {
queryString += " " + logic + " " + field + " "
+ handleExpression(expression) + " ? ";
params.add(para);
}
return this;
}
public IQueryObject addQuery(String scope, Object[] paras) {
if (scope != null) {
queryString += " and " + scope;
if (paras != null && paras.length > 0) {
for (int i = 0; i < paras.length; i++)
params.add(paras[i]);
}
}
return this;
}
private String handleExpression(String expression) {
if (expression == null)
return "=";
else
return expression;
}
public void customizeQuery() {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -