Skip to content

Commit

Permalink
Merge pull request #28 from jujiale/main
Browse files Browse the repository at this point in the history
feat: add more paths for controller register
  • Loading branch information
stateIs0 authored Feb 4, 2024
2 parents 8d802a1 + 9bd4322 commit a8cd4bf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void doScan(Method declaredMethod,
String[] params = r.params;
String[] headers = r.headers;
String[] path = r.path;
String pathFinal = RequestMappingInfoWrapper.buildPath(parentPath, path);
String[] pathFinal = RequestMappingInfoWrapper.buildPath(parentPath, path);
resultList.add(new RequestMappingInfoWrapper(RequestMappingInfo
.paths(pathFinal)
.methods(methods)
Expand Down Expand Up @@ -97,25 +97,33 @@ interface Handler {
public static class RequestMappingInfoWrapper {
public RequestMappingInfo requestMappingInfo;
public Method method;
public String path;
public String[] path;

public RequestMappingInfoWrapper(RequestMappingInfo requestMappingInfo, Method method, String path) {
public RequestMappingInfoWrapper(RequestMappingInfo requestMappingInfo, Method method, String[] path) {
this.requestMappingInfo = requestMappingInfo;
this.method = method;
this.path = path;
}

public static String buildPath(String[] parent, String[] subPath) {
if (subPath.length == 0) {
subPath = new String[]{"/"};
public static String[] buildPath(String[] parent, String[] subPath) {
List<String> paths = new ArrayList<>();

if (parent == null || parent.length == 0) {
return subPath;
}
if (parent.length == 0) {
parent = new String[]{"/"};

if (subPath == null || subPath.length == 0) {
return parent;
}
if (subPath[0].startsWith("/")) {
return parent[0] + subPath[0];

for (String parentPath : parent) {
for (String subPathValue : subPath) {
String combinedPath = (parentPath.endsWith("/") ? parentPath : parentPath + "/") +
(subPathValue.startsWith("/") ? subPathValue.substring(1) : subPathValue);
paths.add(combinedPath);
}
}
return parent[0] + "/" + subPath[0];
return paths.toArray(new String[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void doScan(Method declaredMethod,
String[] params = r.params;
String[] headers = r.headers;
String[] path = r.path;
String pathFinal = RequestMappingInfoWrapper.buildPath(parentPath, path);
String[] pathFinal = RequestMappingInfoWrapper.buildPath(parentPath, path);
resultList.add(new RequestMappingInfoWrapper(RequestMappingInfo
.paths(pathFinal)
.methods(methods)
Expand Down Expand Up @@ -97,25 +97,33 @@ interface Handler {
public static class RequestMappingInfoWrapper {
public RequestMappingInfo requestMappingInfo;
public Method method;
public String path;
public String[] path;

public RequestMappingInfoWrapper(RequestMappingInfo requestMappingInfo, Method method, String path) {
public RequestMappingInfoWrapper(RequestMappingInfo requestMappingInfo, Method method, String[] path) {
this.requestMappingInfo = requestMappingInfo;
this.method = method;
this.path = path;
}

public static String buildPath(String[] parent, String[] subPath) {
if (subPath.length == 0) {
subPath = new String[]{"/"};
public static String[] buildPath(String[] parent, String[] subPath) {
List<String> paths = new ArrayList<>();

if (parent == null || parent.length == 0) {
return subPath;
}
if (parent.length == 0) {
parent = new String[]{"/"};

if (subPath == null || subPath.length == 0) {
return parent;
}
if (subPath[0].startsWith("/")) {
return parent[0] + subPath[0];

for (String parentPath : parent) {
for (String subPathValue : subPath) {
String combinedPath = (parentPath.endsWith("/") ? parentPath : parentPath + "/") +
(subPathValue.startsWith("/") ? subPathValue.substring(1) : subPathValue);
paths.add(combinedPath);
}
}
return parent[0] + "/" + subPath[0];
return paths.toArray(new String[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void doScan(Method declaredMethod,
String[] params = r.params;
String[] headers = r.headers;
String[] path = r.path;
String pathFinal = RequestMappingInfoWrapper.buildPath(parentPath, path);
String[] pathFinal = RequestMappingInfoWrapper.buildPath(parentPath, path);
resultList.add(new RequestMappingInfoWrapper(RequestMappingInfo
.paths(pathFinal)
.methods(methods)
Expand Down Expand Up @@ -98,25 +98,33 @@ interface Handler {
public static class RequestMappingInfoWrapper {
public RequestMappingInfo requestMappingInfo;
public Method method;
public String path;
public String[] path;

public RequestMappingInfoWrapper(RequestMappingInfo requestMappingInfo, Method method, String path) {
public RequestMappingInfoWrapper(RequestMappingInfo requestMappingInfo, Method method, String[] path) {
this.requestMappingInfo = requestMappingInfo;
this.method = method;
this.path = path;
}

public static String buildPath(String[] parent, String[] subPath) {
if (subPath.length == 0) {
subPath = new String[]{"/"};
public static String[] buildPath(String[] parent, String[] subPath) {
List<String> paths = new ArrayList<>();

if (parent == null || parent.length == 0) {
return subPath;
}
if (parent.length == 0) {
parent = new String[]{"/"};

if (subPath == null || subPath.length == 0) {
return parent;
}
if (subPath[0].startsWith("/")) {
return parent[0] + subPath[0];

for (String parentPath : parent) {
for (String subPathValue : subPath) {
String combinedPath = (parentPath.endsWith("/") ? parentPath : parentPath + "/") +
(subPathValue.startsWith("/") ? subPathValue.substring(1) : subPathValue);
paths.add(combinedPath);
}
}
return parent[0] + "/" + subPath[0];
return paths.toArray(new String[0]);
}
}

Expand Down

0 comments on commit a8cd4bf

Please sign in to comment.