Skip to content

Commit d04e848

Browse files
committed
fix getKeyType bug
1 parent 085669d commit d04e848

File tree

13 files changed

+101
-17
lines changed

13 files changed

+101
-17
lines changed

example/example-application/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-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.0.dev2</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-domain/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-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.0.dev2</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-flow/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-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.0.dev2</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-infra-jpa/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-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.0.dev2</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/example-server/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-example</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>3.3.0.dev2</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<parent>
1414
<groupId>com.codingapi.springboot</groupId>
1515
<artifactId>springboot-parent</artifactId>
16-
<version>3.3.0.dev2</version>
16+
<version>3.3.1</version>
1717
</parent>
1818

1919
<artifactId>springboot-example</artifactId>
20-
<version>3.3.0.dev2</version>
20+
<version>3.3.1</version>
2121

2222
<name>springboot-example</name>
2323
<description>springboot-example project for Spring Boot</description>

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>3.3.0.dev2</version>
15+
<version>3.3.1</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>3.3.0.dev2</version>
8+
<version>3.3.1</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

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

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,30 @@ public void addFilter(String key, List<String> value) {
139139
private Class<?> getKeyType(String key) {
140140
String[] keys = key.split("\\.");
141141
Class<?> keyClass = clazz;
142+
142143
for (String k : keys) {
143-
Field[] fields = keyClass.getDeclaredFields();
144+
keyClass = findFieldInHierarchy(keyClass, k);
145+
146+
if (keyClass == null) {
147+
throw new IllegalArgumentException("Field " + k + " not found in class hierarchy.");
148+
}
149+
}
150+
return keyClass;
151+
}
152+
153+
private Class<?> findFieldInHierarchy(Class<?> clazz, String fieldName) {
154+
Class<?> currentClass = clazz;
155+
156+
while (currentClass != null) {
157+
Field[] fields = currentClass.getDeclaredFields();
144158
for (Field field : fields) {
145-
if (field.getName().equals(k)) {
146-
keyClass = field.getType();
147-
break;
159+
if (field.getName().equals(fieldName)) {
160+
return field.getType();
148161
}
149162
}
163+
currentClass = currentClass.getSuperclass(); // 向上查找父类
150164
}
151-
return keyClass;
165+
return null;
152166
}
153167

154168
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.codingapi.springboot.framework.dto.request;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import org.apache.commons.io.FileUtils;
6+
import org.apache.logging.log4j.util.PropertiesUtil;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.lang.reflect.Field;
10+
import java.util.Properties;
11+
12+
import static org.junit.jupiter.api.Assertions.*;
13+
14+
class SearchRequestTest {
15+
16+
17+
18+
@Test
19+
void test(){
20+
Class<?> type = getKeyType(Demo.class,"deleted");
21+
System.out.println(type);
22+
}
23+
24+
private Class<?> getKeyType(Class<?> clazz, String key) {
25+
String[] keys = key.split("\\.");
26+
Class<?> keyClass = clazz;
27+
28+
for (String k : keys) {
29+
keyClass = findFieldInHierarchy(keyClass, k);
30+
31+
if (keyClass == null) {
32+
throw new IllegalArgumentException("Field " + k + " not found in class hierarchy.");
33+
}
34+
}
35+
return keyClass;
36+
}
37+
38+
private Class<?> findFieldInHierarchy(Class<?> clazz, String fieldName) {
39+
Class<?> currentClass = clazz;
40+
41+
while (currentClass != null) {
42+
Field[] fields = currentClass.getDeclaredFields();
43+
for (Field field : fields) {
44+
if (field.getName().equals(fieldName)) {
45+
return field.getType();
46+
}
47+
}
48+
currentClass = currentClass.getSuperclass(); // 向上查找父类
49+
}
50+
return null;
51+
}
52+
53+
54+
@Setter
55+
@Getter
56+
public class Demo extends BaseEntity{
57+
58+
private long id;
59+
private String name;
60+
61+
}
62+
63+
@Setter
64+
@Getter
65+
public class BaseEntity{
66+
67+
private int state;
68+
private boolean deleted;
69+
}
70+
}

0 commit comments

Comments
 (0)