Skip to content

Commit 004a90e

Browse files
committed
add not equal
1 parent 84d96a9 commit 004a90e

File tree

10 files changed

+43
-10
lines changed

10 files changed

+43
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>com.codingapi.springboot</groupId>
1414
<artifactId>springboot-parent</artifactId>
15-
<version>2.9.7</version>
15+
<version>2.9.8</version>
1616

1717
<url>https://github.com/codingapi/springboot-framewrok</url>
1818
<name>springboot-parent</name>

springboot-starter-data-fast/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>2.9.7</version>
8+
<version>2.9.8</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/jpa/repository/DynamicSQLBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ private void buildSQL(Filter filter, StringBuilder hql) {
9898
params.add(filter.getValue()[0]);
9999
paramIndex++;
100100
}
101+
102+
if (filter.isNotEqual()) {
103+
hql.append(filter.getKey()).append(" != ?").append(paramIndex);
104+
params.add(filter.getValue()[0]);
105+
paramIndex++;
106+
}
107+
101108
if (filter.isLike()) {
102109
hql.append(filter.getKey()).append(" LIKE ?").append(paramIndex);
103110
params.add("%" + filter.getValue()[0] + "%");

springboot-starter-data-fast/src/test/java/com/codingapi/springboot/fast/DemoRepositoryTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ void findAll() {
5656
assertEquals(1, page.getTotalElements());
5757
}
5858

59+
@Test
60+
void pageRequestNotEqual() {
61+
demoRepository.deleteAll();
62+
Demo demo1 = new Demo();
63+
demo1.setName("123");
64+
demo1 = demoRepository.save(demo1);
65+
66+
Demo demo2 = new Demo();
67+
demo2.setName("456");
68+
demoRepository.save(demo2);
69+
70+
PageRequest request = new PageRequest();
71+
request.setCurrent(1);
72+
request.setPageSize(10);
73+
request.addFilter("id", Relation.NOT_EQUAL, demo1.getId());
74+
75+
Page<Demo> page = demoRepository.pageRequest(request);
76+
assertEquals(1, page.getTotalElements());
77+
}
5978

6079
@Test
6180
void pageRequest() {

springboot-starter-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.9.7</version>
9+
<version>2.9.8</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

springboot-starter-security/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.9.7</version>
9+
<version>2.9.8</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>2.9.7</version>
8+
<version>2.9.8</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request/Filter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public boolean isEqual() {
4848
return relation == Relation.EQUAL;
4949
}
5050

51+
public boolean isNotEqual() {
52+
return relation == Relation.NOT_EQUAL;
53+
}
54+
5155
public boolean isLike() {
5256
return relation == Relation.LIKE;
5357
}

springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request/Relation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public enum Relation {
44

5+
NOT_EQUAL,
56
EQUAL,
67
LIKE,
78
LEFT_LIKE,

springboot-starter/src/main/java/com/codingapi/springboot/framework/dto/request/SearchRequest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,13 @@ public PageRequest toPageRequest(Class<?> clazz) {
224224
if (JSON.isValid(filter)) {
225225
removeKeys.add("filter");
226226
JSONObject jsonObject = JSON.parseObject(filter);
227-
for (String key : jsonObject.keySet()) {
228-
JSONArray value = jsonObject.getJSONArray(key);
229-
if (value != null && !value.isEmpty()) {
230-
List<String> values = value.stream().map(Object::toString).collect(Collectors.toList());
231-
content.addFilter(key, values);
227+
if(jsonObject!=null) {
228+
for (String key : jsonObject.keySet()) {
229+
JSONArray value = jsonObject.getJSONArray(key);
230+
if (value != null && !value.isEmpty()) {
231+
List<String> values = value.stream().map(Object::toString).collect(Collectors.toList());
232+
content.addFilter(key, values);
233+
}
232234
}
233235
}
234236
}

0 commit comments

Comments
 (0)