Skip to content

Commit 53b8d77

Browse files
committed
support search isNull isNotNull notIn
1 parent 78e5872 commit 53b8d77

File tree

11 files changed

+98
-9
lines changed

11 files changed

+98
-9
lines changed

pom.xml

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

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>2.9.31</version>
18+
<version>2.9.32</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/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.31</version>
9+
<version>2.9.32</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-data-authorization</artifactId>

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.31</version>
8+
<version>2.9.32</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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ private void buildSQL(Filter filter, StringBuilder hql) {
9999
paramIndex++;
100100
}
101101

102+
if (filter.isNull()) {
103+
hql.append(filter.getKey()).append(" IS NULL ");
104+
}
105+
106+
if (filter.isNotNull()) {
107+
hql.append(filter.getKey()).append(" IS NOT NULL ");
108+
}
109+
102110
if (filter.isNotEqual()) {
103111
hql.append(filter.getKey()).append(" != ?").append(paramIndex);
104112
params.add(filter.getValue()[0]);
@@ -125,6 +133,13 @@ private void buildSQL(Filter filter, StringBuilder hql) {
125133
params.add(Arrays.asList(filter.getValue()));
126134
paramIndex++;
127135
}
136+
137+
if (filter.isNotIn()) {
138+
hql.append(filter.getKey()).append(" NOT IN (").append("?").append(paramIndex).append(")");
139+
params.add(Arrays.asList(filter.getValue()));
140+
paramIndex++;
141+
}
142+
128143
if (filter.isGreaterThan()) {
129144
hql.append(filter.getKey()).append(" > ?").append(paramIndex);
130145
params.add(filter.getValue()[0]);

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

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

59+
@Test
60+
void pageRequestIsNull() {
61+
demoRepository.deleteAll();
62+
Demo demo1 = new Demo();
63+
demo1.setName("123");
64+
demo1 = demoRepository.save(demo1);
65+
66+
Demo demo2 = new Demo();
67+
demoRepository.save(demo2);
68+
69+
PageRequest request = new PageRequest();
70+
request.setCurrent(1);
71+
request.setPageSize(10);
72+
request.addFilter("name", Relation.IS_NULL);
73+
74+
Page<Demo> page = demoRepository.pageRequest(request);
75+
assertEquals(1, page.getTotalElements());
76+
}
77+
78+
@Test
79+
void pageRequestIsNotNull() {
80+
demoRepository.deleteAll();
81+
Demo demo1 = new Demo();
82+
demo1.setName("123");
83+
demo1 = demoRepository.save(demo1);
84+
85+
Demo demo2 = new Demo();
86+
demoRepository.save(demo2);
87+
88+
PageRequest request = new PageRequest();
89+
request.setCurrent(1);
90+
request.setPageSize(10);
91+
request.addFilter("name", Relation.IS_NOT_NULL);
92+
93+
Page<Demo> page = demoRepository.pageRequest(request);
94+
assertEquals(1, page.getTotalElements());
95+
}
96+
5997
@Test
6098
void pageRequestNotEqual() {
6199
demoRepository.deleteAll();
@@ -115,8 +153,29 @@ void customInSearch() {
115153
request.addFilter("id", Relation.IN, 1, 2, 3);
116154

117155
Page<Demo> page = demoRepository.pageRequest(request);
118-
log.info("demo:{}", page.getContent());
119-
// assertEquals(2, page.getTotalElements());
156+
assertEquals(2, page.getTotalElements());
157+
}
158+
159+
160+
@Test
161+
void customNotInSearch() {
162+
demoRepository.deleteAll();
163+
Demo demo1 = new Demo();
164+
demo1.setName("123");
165+
demoRepository.save(demo1);
166+
167+
Demo demo2 = new Demo();
168+
demo2.setName("456");
169+
demoRepository.save(demo2);
170+
171+
PageRequest request = new PageRequest();
172+
request.setCurrent(1);
173+
request.setPageSize(10);
174+
175+
request.addFilter("id", Relation.NOT_IN, 3);
176+
177+
Page<Demo> page = demoRepository.pageRequest(request);
178+
assertEquals(2, page.getTotalElements());
120179
}
121180

122181

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.31</version>
9+
<version>2.9.32</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.31</version>
9+
<version>2.9.32</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.31</version>
8+
<version>2.9.32</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

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

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

51+
public boolean isNull() {
52+
return relation == Relation.IS_NULL;
53+
}
54+
55+
public boolean isNotNull() {
56+
return relation == Relation.IS_NOT_NULL;
57+
}
58+
59+
public boolean isNotIn() {
60+
return relation == Relation.NOT_IN;
61+
}
62+
5163
public boolean isNotEqual() {
5264
return relation == Relation.NOT_EQUAL;
5365
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public enum Relation {
99
RIGHT_LIKE,
1010
BETWEEN,
1111
IN,
12+
NOT_IN,
13+
IS_NULL,
14+
IS_NOT_NULL,
1215
GREATER_THAN,
1316
LESS_THAN,
1417
GREATER_THAN_EQUAL,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
------------------------------------------------------
2-
CodingApi SpringBoot-Starter 2.9.31
2+
CodingApi SpringBoot-Starter 2.9.32
33
springboot version (${spring-boot.version})
44
------------------------------------------------------

0 commit comments

Comments
 (0)