# QmData-API

在2.1.x版本之后,增加where条件和orderby条件自定义传入,对应的API也会有相应的重载方法。

# 通用自动查询列表

autoSelectList

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table)
where where的SQL语句,不需要前置 WHERE 命令。
orderBy orderBy的SQL语句,不需要前置的 ORDER BY 命令。注意当实体类中标注@OrderBy时,优先使用参数列表的orderBy进行查询。
Class 对应表的实体类的Class

说明

根据实体类字段自动构建查询条件,返回对象集合。

# 通用查询单条记录

autoSelectOne

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table)
where where的SQL语句,不需要前置 WHERE 命令。
orderBy orderBy的SQL语句,不需要前置的 ORDER BY 命令。注意当实体类中标注@OrderBy时,优先使用参数列表的orderBy进行查询。
Class 对应表的实体类的Class

说明

根据实体类字段自动构建查询条件,返回对象。

# 通用插入记录

autoInsert

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table和@Id)

说明

根据实体类字段自动构建插入SQL,返回影响行数。

# 通用插入记录(返回主键)

autoInsertGetPrimaryKey

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table和@Id)

说明

根据实体类字段自动构建插入SQL,返回ResultInsert对象,ResultInsert对象包含影响行数和主键。

# 通用修改记录

autoUpdate

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table和@Id)
where where的SQL语句,不需要前置 WHERE 命令。注意它的前置条件一定会有主键。

说明

根据实体类字段自动构建更新SQL,返回影响行数。

注意:该更新只会通过主键进行更新,如果主键为空,或者实体类中没有带上@Id的注解,则会直接抛出异常。

# 通用删除记录

autoDelete

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table)
where where的SQL语句,不需要前置 WHERE 命令。

说明

根据实体类字段自动构建删除SQL,返回影响行数。

# 通用查询记录数

autoSelectCount

参数列表

参数 说明
entity 对应表的实体类(必须带有@Table)
where where的SQL语句,不需要前置 WHERE 命令。

说明

根据实体类字段自动构建查询SQL,返回记录数。

# API-接口源码

public interface QmData {

    /**
     * 通用查询列表
     *
     * @param entity 对应表的实体类(必须带有@Table)
     * @param clamm  对应表的实体类的Class
     * @return 根据参数指定的类型进行嵌套数据
     */
    <Q> List<Q> autoSelectList(Q entity, Class<Q> clamm);

    /**
     * 通用查询单条记录
     *
     * @param entity 实体类(必须带有@Table)
     * @param clamm  实体类class对象
     * @return 根据参数指定的类型进行嵌套数据
     */
    <Q> Q autoSelectOne(Q entity, Class<Q> clamm);


    /**
     * 通用插入记录
     *
     * @param entity 对应表的实体类(必须带有@Table和@Id)
     * @return 影响行数
     */
    <Q> int autoInsert(Q entity);

    /**
     * 通用插入记录 (返回主键)
     *
     * @param entity 对应表的实体类(必须带有@Table和@Id)
     * @return ResultInsert 返回带新增主键id的对象
     */
    <Q> ResultInsert autoInsertGetPrimaryKey(Q entity);

    /**
     * 通用修改记录
     *
     * @param entity 对应表的实体类(必须带有@Table和@Id)
     * @return 影响行数
     */
    <Q> int autoUpdate(Q entity);


    /**
     * 通用删除记录
     *
     * @param entity 对应表的实体类(必须带有@Table)
     * @return 影响行数
     */
    <Q> int autoDelete(Q entity);


    /**
     * 通用查询记录数
     *
     * @param entity 对应表的实体类(必须带有@Table)
     * @return 影响行数
     */
    <Q> int autoSelectCount(Q entity);

    // --------------where 重载------------------


    /**
     * 通用查询列表
     *
     * @param entity 对应表的实体类(必须带有@Table)
     * @param where  条件sql
     * @param clamm  对应表的实体类的Class
     * @return 根据参数指定的类型进行嵌套数据
     */
    <Q> List<Q> autoSelectList(Q entity, String where, Class<Q> clamm);


    /**
     * 通用查询单条记录
     *
     * @param entity 实体类(必须带有@Table)
     * @param where  条件sql
     * @param clamm  实体类class对象
     * @return 根据参数指定的类型进行嵌套数据
     */
    <Q> Q autoSelectOne(Q entity, String where, Class<Q> clamm);


    /**
     * 通用修改记录
     *
     * @param entity 对应表的实体类(必须带有@Table和@Id)
     * @param where  条件sql
     * @return 影响行数
     */
    <Q> int autoUpdate(Q entity, String where);


    /**
     * 通用删除记录
     *
     * @param entity 对应表的实体类(必须带有@Table)
     * @param where  条件sql
     * @return 影响行数
     */
    <Q> int autoDelete(Q entity, String where);


    /**
     * 通用查询记录数
     *
     * @param entity   对应表的实体类(必须带有@Table)
     * @param whereSql 条件sql
     * @param <Q>
     * @return 影响行数
     */
    <Q> int autoSelectCount(Q entity, String whereSql);

    // -------------where orderby 重载 --------------------

    /**
     * 通用查询列表
     *
     * @param entity  对应表的实体类(必须带有@Table)
     * @param where   条件sql
     * @param orderBy 排序sql
     * @param clamm   对应表的实体类的Class
     * @return 根据参数指定的类型进行嵌套数据
     */
    <Q> List<Q> autoSelectList(Q entity, String where, String orderBy, Class<Q> clamm);


    /**
     * 通用查询单条记录
     *
     * @param entity  实体类(必须带有@Table)
     * @param where   条件sql
     * @param orderBy 排序sql
     * @param clamm   实体类class对象
     * @return 根据参数指定的类型进行嵌套数据
     */
    <Q> Q autoSelectOne(Q entity, String where, String orderBy, Class<Q> clamm);

    // -----------1.x 兼容接口 -------------

    /**
     * 查询列表
     *
     * @param sqlName 命名空间
     * @param params  参数
     * @return 根据返回指定的类型进行嵌套数据
     */
    @Deprecated
    <Q> List<Q> selectList(String sqlName, Object params);

    /**
     * 查询单条记录
     *
     * @param sqlName 命名空间
     * @param params  参数
     * @return 根据返回指定的类型进行嵌套数据
     */
    @Deprecated
    <Q> Q selectOne(String sqlName, Object params);


    /**
     * 插入记录
     *
     * @param sqlName 命名空间
     * @param params  参数
     * @return 影响行数
     */
    @Deprecated
    int insert(String sqlName, Object params);

    /**
     * 修改记录
     *
     * @param sqlName 命名空间
     * @param params  参数
     * @return 影响行数
     */
    @Deprecated
    int update(String sqlName, Object params);

    /**
     * 删除记录
     *
     * @param sqlName 命名空间
     * @param params  参数
     * @return 影响行数
     */
    @Deprecated
    int delete(String sqlName, Object params);

}
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
最近更新: 2019/12/29 上午7:41:19