Skip to content

Commit 65416b3

Browse files
committed
docs: 调整示例代码,简化示例数据
1 parent d18b441 commit 65416b3

File tree

4 files changed

+69
-49
lines changed

4 files changed

+69
-49
lines changed

eaphone-spring-data-query-samples/src/main/java/com/eaphonetech/common/datatables/samples/mongo/document/Order.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.eaphonetech.common.datatables.samples.mongo.document;
22

3+
import java.util.ArrayList;
34
import java.util.Calendar;
45
import java.util.Date;
5-
import java.util.HashSet;
6+
import java.util.List;
67
import java.util.Random;
7-
import java.util.Set;
88

99
import org.bson.types.ObjectId;
1010
import org.springframework.data.annotation.Id;
@@ -47,7 +47,7 @@ public class Order {
4747
private double price;
4848

4949
@JsonView(QueryOutput.View.class)
50-
private Set<OrderItem> items;
50+
private List<OrderItem> items;
5151

5252
@Transient
5353
public static Order random() {
@@ -62,29 +62,27 @@ public static Order random() {
6262

6363
o.isValid = r.nextBoolean();
6464

65-
o.amount = r.nextInt(25);
66-
6765
o.price = Math.round(100.0 * 100.0 * r.nextDouble()) / 100.0;
6866

69-
Set<OrderItem> items = new HashSet<>();
70-
for (int i = 0; i < r.nextInt(8); i++) {
71-
int amount = r.nextInt(25);
72-
double price = Math.round(100.0 * 100.0 * r.nextDouble()) / 100.0;
67+
List<OrderItem> items = new ArrayList<>();
68+
int itemsCount = r.nextInt(5);
69+
int preciseTotalPrice = 0;
70+
for (int i = 0; i < itemsCount; i++) {
71+
int preciseItemPrice = r.nextInt(10000);
7372

7473
OrderItem item = new OrderItem();
7574
item.setId(new ObjectId().toHexString());
7675
item.setName(o.getOrderNumber() + "_" + i);
77-
item.setAmount(amount);
78-
item.setPrice(price);
79-
item.setDate(o.getDate());
80-
item.setValid(o.isValid());
76+
item.setPrice((double) preciseItemPrice / 100.0);
8177
items.add(item);
8278

83-
o.setAmount(o.getAmount() + amount);
84-
o.setPrice(o.getPrice() + price);
79+
preciseTotalPrice += preciseItemPrice;
8580
}
81+
o.setPrice((double) preciseTotalPrice / 100.0);
8682
o.setItems(items);
8783

84+
o.amount = itemsCount;
85+
8886
return o;
8987
}
9088
}
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package com.eaphonetech.common.datatables.samples.mongo.document;
22

3-
import java.util.Date;
4-
53
import org.springframework.data.mongodb.core.mapping.Field;
64

75
import com.eaphonetech.common.datatables.model.mapping.QueryOutput;
8-
import com.fasterxml.jackson.annotation.JsonFormat;
96
import com.fasterxml.jackson.annotation.JsonView;
107

118
import lombok.Data;
@@ -20,17 +17,6 @@ public class OrderItem {
2017
@JsonView(QueryOutput.View.class)
2118
private String name;
2219

23-
@JsonView(QueryOutput.View.class)
24-
private int amount;
25-
2620
@JsonView(QueryOutput.View.class)
2721
private double price;
28-
29-
@JsonFormat(pattern = "yyyy-MM-dd")
30-
@JsonView(QueryOutput.View.class)
31-
private Date date;
32-
33-
@JsonView(QueryOutput.View.class)
34-
private boolean isValid;
35-
3622
}

eaphone-spring-data-query-samples/src/main/resources/static/index.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
<head>
55
<title>Eaphone Query Example</title>
6-
<!--
76
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css" />
8-
<link rel="stylesheet" href="/webjars/highlightjs/styles/solarized-light.css" />
9-
-->
7+
<link rel="stylesheet" href="/webjars/highlightjs/styles/solarized-light.min.css" />
8+
<!--
109
<link href="https://cdn.bootcss.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
1110
<link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/solarized-light.min.css" rel="stylesheet">
11+
-->
1212
<link rel="stylesheet" href="css/style.css">
1313
</head>
1414

@@ -45,7 +45,7 @@ <h5 class="card-header">Request</h5>
4545
<div class="card mb-4">
4646
<h5 class="card-header">Rendered Grid</h5>
4747
<div class="card-body">
48-
<table class="table table-bordered table-striped table-sm">
48+
<table class="table table-bordered table-striped table-sm text-center">
4949
<thead>
5050
<tr>
5151
<th scope="col">i</th>
@@ -75,9 +75,15 @@ <h5 class="card-header">Server Response</h5>
7575
</div>
7676
</div>
7777
</div>
78+
79+
<script src="/webjars/jquery/jquery.min.js"></script>
80+
<script src="/webjars/bootstrap/js/bootstrap.min.js"></script>
81+
<script src="/webjars/highlightjs/highlight.min.js"></script>
82+
<!--
7883
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
7984
<script src="https://cdn.bootcss.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
8085
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
86+
-->
8187
<script type="text/javascript" src="/js/index.js"></script>
8288
</body>
8389

eaphone-spring-data-query-samples/src/main/resources/static/js/index.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ $(document).ready(function () {
2626
}
2727
}
2828
}
29+
}, {
30+
summary: 'Single regex filter',
31+
description: 'Filter with regular expression',
32+
value: {
33+
where: {
34+
orderNumber: {
35+
'_regex': 'O1..[25].*'
36+
}
37+
}
38+
}
39+
}, {
40+
summary: 'SQL Like',
41+
description: 'Query using SQL like (%)',
42+
value: {
43+
where: {
44+
"orderNumber": {
45+
"_like": "O100%"
46+
}
47+
}
48+
}
2949
}, {
3050
summary: 'Single comparison filter',
3151
description: 'Comparison filter on single column',
@@ -46,13 +66,23 @@ $(document).ready(function () {
4666
}
4767
}
4868
}
69+
}, {
70+
summary: 'Boolean search',
71+
description: 'Search with boolean values',
72+
value: {
73+
where: {
74+
isValid: {
75+
'_eq': true
76+
}
77+
}
78+
}
4979
}, {
5080
summary: 'Enumeration (in)',
5181
description: 'Enumeration with number',
5282
value: {
5383
where: {
5484
amount: {
55-
'_in': [5, 9, 13]
85+
'_in': [2, 3, 5]
5686
}
5787
}
5888
}
@@ -62,22 +92,32 @@ $(document).ready(function () {
6292
value: {
6393
where: {
6494
price: {
65-
'_gte': 10,
66-
'_lt': 20.5
95+
'_gte': 50,
96+
'_lt': 200
6797
}
6898
}
6999
}
70100
}, {
71101
summary: 'Multiple columns',
72-
description: 'More where on multiple columns',
102+
description: 'More criteria on multiple columns (AND)',
73103
value: {
74104
where: {
75105
date: {
76106
'_gt': '2012-01-01'
77107
},
78108
price: {
79-
'_gte': 10,
80-
'_lt': 20.5
109+
'_gte': 50,
110+
'_lt': 200
111+
}
112+
}
113+
}
114+
}, {
115+
summary: 'Empty array',
116+
description: 'Search for empty array',
117+
value: {
118+
where: {
119+
items: {
120+
'_eq': []
81121
}
82122
}
83123
}
@@ -103,16 +143,6 @@ $(document).ready(function () {
103143
'price': 'asc'
104144
}]
105145
}
106-
}, {
107-
summary: 'Like',
108-
description: 'SQL like',
109-
value: {
110-
where: {
111-
"orderNumber": {
112-
"_like": "O100%"
113-
}
114-
}
115-
}
116146
}];
117147

118148
/** Draw example buttons */

0 commit comments

Comments
 (0)