MCPcopy Create free account
hub / github.com/LisenCoding/cangku / Query

Class Query

boot/src/main/java/com/utils/Query.java:14–98  ·  view source on GitHub ↗

查询参数

Source from the content-addressed store, hash-verified

12 * 查询参数
13 */
14public class Query<T> extends LinkedHashMap<String, Object> {
15 private static final long serialVersionUID = 1L;
16 /**
17 * mybatis-plus分页参数
18 */
19 private Page<T> page;
20 /**
21 * 当前页码
22 */
23 private int currPage = 1;
24 /**
25 * 每页条数
26 */
27 private int limit = 10;
28
29 public Query(JQPageInfo pageInfo) {
30 //分页参数
31 if(pageInfo.getPage()!= null){
32 currPage = pageInfo.getPage();
33 }
34 if(pageInfo.getLimit()!= null){
35 limit = pageInfo.getLimit();
36 }
37
38
39 //防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
40 String sidx = SQLFilter.sqlInject(pageInfo.getSidx());
41 String order = SQLFilter.sqlInject(pageInfo.getOrder());
42
43
44 //mybatis-plus分页
45 this.page = new Page<>(currPage, limit);
46
47 //排序
48 if(StringUtils.isNotBlank(sidx) && StringUtils.isNotBlank(order)){
49 this.page.setOrderByField(sidx);
50 this.page.setAsc("ASC".equalsIgnoreCase(order));
51 }
52 }
53
54
55 public Query(Map<String, Object> params){
56 this.putAll(params);
57
58 //分页参数
59 if(params.get("page") != null){
60 currPage = Integer.parseInt(String.valueOf(params.get("page")));
61 }
62 if(params.get("limit") != null){
63 limit = Integer.parseInt(String.valueOf(params.get("limit")));
64 }
65
66 this.put("offset", (currPage - 1) * limit);
67 this.put("page", currPage);
68 this.put("limit", limit);
69
70 //防止SQL注入(因为sidx、order是通过拼接SQL实现排序的,会有SQL注入风险)
71 String sidx = SQLFilter.sqlInject((String)params.get("sidx"));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected