4
hao
2025-04-16 c5fb1fbcbb2bf4d511773d348f9ef625855c61fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.app.query.dao;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * sql参数
 * @author tanxiang
 *
 * @param <T>
 */
public class SQLParameter<T> {
    public final static int DEFAULT_PAG = 1;
    public final static int DEFAULT_PAGESIZE = 10000;
    /**
     * 页码
     */
    private int page = DEFAULT_PAG;
    /**
     * 页大小
     */
    private int pageSize = DEFAULT_PAGESIZE;
 
    public SQLParameter() {
    }
 
    public static <T> SQLParameter<T> newInstance() {
        return new SQLParameter<T>();
    }
 
    public static <T> SQLParameter<T> newInstance(Class<T> cls) {
        return new SQLParameter<T>();
    }
 
    public SQLParameter<T> clear() {
        list.clear();
        return this;
    }
 
    public SQLParameter<T> reset() {
        this.page = DEFAULT_PAG;
        this.pageSize = DEFAULT_PAGESIZE;
        list.clear();
        return this;
    }
 
    private List<T> list = new ArrayList<T>();
 
    public SQLParameter<T> add(T param) {
        list.add(param);
        return this;
    }
 
    public List<T> toList() {
        return list;
    }
 
    public T[] toArray(T[] a) {
        return list.toArray(a);
    }
 
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        Parameter p;
        for (T t : list) {
            if(t instanceof Parameter) {
                p = (Parameter) t;
                map.put(p.getName(), p.getValue());
                continue;
            }
            throw new IllegalArgumentException("Occurs Exception: "+t.getClass().getName() + "is not instanceof com.unind.base.dbconnection.query.Parameter");
        }
        return map;
    }
 
    public int getPage() {
        return page;
    }
    public void setPage(int page) {
        this.page = page;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
 
    public int getStartIndex() {
        return (page-1) * pageSize;
    }
    
}