Skip to content

Commit 2893345

Browse files
author
Weihai Li
committed
2 parents 66ed000 + 42e8a09 commit 2893345

File tree

12 files changed

+1392
-1252
lines changed

12 files changed

+1392
-1252
lines changed

doc/Query.md

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Why #
1+
# Why
22

33
I use DataTables in some projects and wrote SpringMVC server side for it. Later the frontend is rewritten and DataTables is no longer used. Now is the time to refine the protocol for general data-grid query.
44

55
* You can not assign a range via `columns[i][search][value]`, as in SQL: `BETWEEN`.
66
* You can only do regular search OR regex search via `columns[i][search][regex]`, but not `=`, `LIKE`.
77

8-
## Query ##
8+
## Query
99

1010
HTTP POST as `@RequestBody` is recommended:
1111

@@ -32,6 +32,7 @@ HTTP POST as `@RequestBody` is recommended:
3232
"_all": [],
3333
"_regex": "",
3434
"_like": "",
35+
"_notlike": "",
3536
"_exists": true,
3637
"_null": true,
3738
"_empty": true,
@@ -41,39 +42,54 @@ HTTP POST as `@RequestBody` is recommended:
4142
}
4243
```
4344

44-
## Examples ##
45+
## Response format
4546

46-
### Basic Query ###
47+
```json
48+
{
49+
"draw": 1,
50+
"total": 0,
51+
"filtered": 0,
52+
"error": "",
53+
"data": []
54+
}
55+
```
56+
57+
## Examples
58+
59+
### Basic Query
4760

4861
None of the `draw`, `offset`, `limit`, `order_by`, `where` are required, so the basic query is:
4962

5063
```http
51-
POST /search
64+
POST /search HTTP/1.1
65+
Content-Type: application/json
5266
5367
{}
5468
```
5569

5670
e.g. NO parameters are needed.
5771

58-
### Pagination ###
72+
### Pagination
5973

6074
Paging is controlled by `offset` and `limit`, which keeps the same as `SKIP` and `LIMIT` in SQL.
6175

6276
```http
63-
POST /search
77+
POST /search HTTP/1.1
78+
Content-Type: application/json
6479
6580
{
6681
"offset": 30,
6782
"limit": 10
6883
}
6984
```
7085

71-
### Ordering ###
86+
### Ordering
7287

7388
Ordering by one column:
7489

7590
```http
76-
POST /search
91+
POST /search HTTP/1.1
92+
Content-Type: application/json
7793
7894
{
7995
"order_by": [{
@@ -86,7 +102,8 @@ POST /search
86102
Ordering by more columns:
87103

88104
```http
89-
POST /search
105+
POST /search HTTP/1.1
106+
Content-Type: application/json
90107
91108
{
92109
"order_by": [{
@@ -97,12 +114,13 @@ POST /search
97114
}
98115
```
99116

100-
### Filtering ###
117+
### Filtering
101118

102119
* Search by equality
103120

104121
```http
105-
POST /search
122+
POST /search HTTP/1.1
123+
Content-Type: application/json
106124
107125
{
108126
"where": {
@@ -116,7 +134,8 @@ POST /search
116134
* Like (`LIKE %value%`)
117135

118136
```http
119-
POST /search
137+
POST /search HTTP/1.1
138+
Content-Type: application/json
120139
121140
{
122141
"where": {
@@ -130,7 +149,8 @@ POST /search
130149
* By Numerical Range
131150

132151
```http
133-
POST /search
152+
POST /search HTTP/1.1
153+
Content-Type: application/json
134154
135155
{
136156
"where": {
@@ -146,7 +166,8 @@ POST /search
146166
* Date Range & Time Range
147167

148168
```http
149-
POST /search
169+
POST /search HTTP/1.1
170+
Content-Type: application/json
150171
151172
{
152173
"where": {
@@ -162,7 +183,8 @@ POST /search
162183
* In
163184

164185
```http
165-
POST /search
186+
POST /search HTTP/1.1
187+
Content-Type: application/json
166188
167189
{
168190
"where": {
@@ -173,12 +195,13 @@ POST /search
173195
}
174196
```
175197

176-
## Multiple Filters ##
198+
## Multiple Filters
177199

178200
Multiple filters are joined by `AND` logic.
179201

180202
```http
181-
POST /search
203+
POST /search HTTP/1.1
204+
Content-Type: application/json
182205
183206
{
184207
"where": {
@@ -197,6 +220,6 @@ POST /search
197220
198221
```
199222

200-
## References ##
223+
## References
201224

202-
* [DataTables: Server-side processing](https://datatables.net/manual/server-side)
225+
* [DataTables: Server-side processing](https://datatables.net/manual/server-side#Sent-parameters)

doc/Query.zh-CN.md

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# 关于查询 #
1+
# 关于查询
22

33
在实际操作中,在 DataTables 的通信协议的基础上,遇到了一些不足,主要有以下方面:
44

55
* 通过 `columns[i][search][value]` 实现的按列搜索功能,不能指定范围。比如 “指定日期范围” 或者 “大于 xx 的值” 这种场景,无法在统一的一个通信协议里传递
66
* 通过 `columns[i][search][regex]` 只能指定 `普通搜索``按正则表达式搜索` 两种场景,
77

8-
## 查询方式 ##
8+
## 查询方式
99

1010
建议在 POST 接口上通过 `@RequestBody` 方式传入较为完整的查询内容。
1111

@@ -32,6 +32,7 @@
3232
"_all": [],
3333
"_regex": "",
3434
"_like": "",
35+
"_notlike": "",
3536
"_exists": true,
3637
"_null": true,
3738
"_empty": true,
@@ -41,39 +42,54 @@
4142
}
4243
```
4344

44-
## 示例 ##
45+
## 响应
4546

46-
### 最简单的请求 ###
47+
```json
48+
{
49+
"draw": 1,
50+
"total": 0,
51+
"filtered": 0,
52+
"error": "",
53+
"data": []
54+
}
55+
```
56+
57+
## 示例
4758

48-
因为 `draw`, `offset`, `limit`, `order_by`, `where` 全都改为可选的,因此最简单的请求就变成了
59+
### 最简单的请求
60+
61+
因为 `draw`, `offset`, `limit`, `order_by`, `where` 全都改为可选的,因此最简单的请求就变成了:
4962

5063
```http
51-
POST /search
64+
POST /search HTTP/1.1
65+
Content-Type: application/json
5266
5367
{}
5468
```
5569

56-
即:不需要任何参数
70+
即:不需要传任何实际的参数
5771

58-
### 分页 ###
72+
### 分页
5973

60-
单纯分页只需要传入 `offset``limit` (当然如果 `limit` 和后端一致的话也可以不传了)
74+
单纯分页只需要传入 `offset``limit` (当然如果 `limit` 和后端的默认值一致的话也可以不传)。
6175

6276
```http
63-
POST /search
77+
POST /search HTTP/1.1
78+
Content-Type: application/json
6479
6580
{
6681
"offset": 30,
6782
"limit": 10
6883
}
6984
```
7085

71-
### 按某一列排序 ###
86+
### 按某一列排序
7287

7388
最简单的排序:
7489

7590
```http
76-
POST /search
91+
POST /search HTTP/1.1
92+
Content-Type: application/json
7793
7894
{
7995
"order_by": [{
@@ -85,7 +101,8 @@ POST /search
85101
稍微复杂一些的排序(请注意排序的顺序是有意义的,因此使用数组形式):
86102

87103
```http
88-
POST /search
104+
POST /search HTTP/1.1
105+
Content-Type: application/json
89106
90107
{
91108
"order_by": [{
@@ -96,12 +113,13 @@ POST /search
96113
}
97114
```
98115

99-
### 按某一列筛选 ###
116+
### 按某一列筛选
100117

101118
* 精确查询
102119

103120
```http
104-
POST /search
121+
POST /search HTTP/1.1
122+
Content-Type: application/json
105123
106124
{
107125
"where": {
@@ -114,8 +132,11 @@ POST /search
114132

115133
* 模糊查询
116134

135+
在 MongoDB 的实现中,'_like' 会使用 `$regex`, 并且按 SQL 的写法,'%' 会被替换成 '.+'。
136+
117137
```http
118-
POST /search
138+
POST /search HTTP/1.1
139+
Content-Type: application/json
119140
120141
{
121142
"where": {
@@ -129,7 +150,8 @@ POST /search
129150
* 按数值范围
130151

131152
```http
132-
POST /search
153+
POST /search HTTP/1.1
154+
Content-Type: application/json
133155
134156
{
135157
"where": {
@@ -145,7 +167,8 @@ POST /search
145167
* 按时间范围
146168

147169
```http
148-
POST /search
170+
POST /search HTTP/1.1
171+
Content-Type: application/json
149172
150173
{
151174
"where": {
@@ -159,10 +182,11 @@ POST /search
159182
160183
```
161184

162-
* 按枚举 (及 `$in` 操作)
185+
* 按枚举 (及 `_in` 操作)
163186

164187
```http
165-
POST /search
188+
POST /search HTTP/1.1
189+
Content-Type: application/json
166190
167191
{
168192
"where": {
@@ -173,12 +197,13 @@ POST /search
173197
}
174198
```
175199

176-
## 复合查询 ##
200+
## 复合查询
177201

178202
默认多个查询的参数之间是 `AND` 关系。
179203

180204
```http
181-
POST /search
205+
POST /search HTTP/1.1
206+
Content-Type: application/json
182207
183208
{
184209
"where": {
@@ -197,6 +222,6 @@ POST /search
197222
198223
```
199224

200-
## 参考 ##
225+
## 参考
201226

202-
* [DataTables: Server-side processing](https://datatables.net/manual/server-side) 和相应的 [中文版](http://datatables.club/manual/server-side.html)
227+
* [DataTables: Server-side processing](https://datatables.net/manual/server-side#Sent-parameters) 和相应的 [中文版](http://datatables.club/manual/server-side.html)

eaphone-spring-data-query-commons/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.eaphonetech</groupId>
66
<artifactId>eaphone-spring-data-query-parent</artifactId>
7-
<version>2.1.0</version>
7+
<version>2.1.1</version>
88
</parent>
99

1010
<artifactId>eaphone-spring-data-query-commons</artifactId>

0 commit comments

Comments
 (0)