-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
veasion
committed
Jan 7, 2023
1 parent
d020bb5
commit 78f0d50
Showing
10 changed files
with
312 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/main/java/cn/veasion/db/criteria/CommonQueryCriteria.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package cn.veasion.db.criteria; | ||
|
||
import cn.veasion.db.query.OrderParam; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* CommonQueryCriteria | ||
* | ||
* @author luozhuowei | ||
* @date 2023/1/7 | ||
*/ | ||
public class CommonQueryCriteria { | ||
|
||
@AutoCriteria | ||
private Map<String, Object> filters; | ||
|
||
private Integer page; | ||
private Integer size; | ||
|
||
private List<OrderParam> orders; | ||
|
||
public Map<String, Object> getFilters() { | ||
return filters; | ||
} | ||
|
||
public void setFilters(Map<String, Object> filters) { | ||
this.filters = filters; | ||
} | ||
|
||
public Integer getPage() { | ||
return page; | ||
} | ||
|
||
public CommonQueryCriteria setPage(Integer page) { | ||
this.page = page; | ||
return this; | ||
} | ||
|
||
public Integer getSize() { | ||
return size; | ||
} | ||
|
||
public CommonQueryCriteria setSize(Integer size) { | ||
this.size = size; | ||
return this; | ||
} | ||
|
||
public void setOrder(OrderParam orderParam) { | ||
if (orderParam != null) { | ||
if (orders == null) { | ||
orders = new ArrayList<>(); | ||
} | ||
orders.add(orderParam); | ||
} | ||
} | ||
|
||
public List<OrderParam> getOrders() { | ||
return orders; | ||
} | ||
|
||
public void setOrders(List<OrderParam> orders) { | ||
this.orders = orders; | ||
} | ||
|
||
public void withLike(String key) { | ||
withLike(key, true, true); | ||
} | ||
|
||
public void withLike(String key, boolean left, boolean right) { | ||
Object v; | ||
if (filters != null && (v = filters.get(key)) != null) { | ||
String value = v.toString().trim(); | ||
if ("".equals(value)) { | ||
return; | ||
} | ||
if (left && !value.startsWith("%")) { | ||
value = "%" + value; | ||
} | ||
if (right && !value.endsWith("%")) { | ||
value += "%"; | ||
} | ||
filters.put(key, value); | ||
} | ||
} | ||
|
||
public CommonQueryCriteria addFilter(String key, Object value) { | ||
if (filters == null) { | ||
filters = new HashMap<>(); | ||
} | ||
filters.put(key, value); | ||
return this; | ||
} | ||
|
||
public CommonQueryCriteria gte(String key, Object value) { | ||
return addFilter("start_" + key, value); | ||
} | ||
|
||
public CommonQueryCriteria lte(String key, Object value) { | ||
return addFilter("end_" + key, value); | ||
} | ||
|
||
public Object remove(String key) { | ||
if (filters != null) { | ||
return filters.remove(key); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.