Skip to content

Commit 0259a93

Browse files
committed
fix: sub ui.data not found
1 parent cbfa3ba commit 0259a93

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

boot/src/main/java/com/reajason/javaweb/boot/controller/ViewController.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import jakarta.servlet.http.HttpServletRequest;
44
import jakarta.servlet.http.HttpServletResponse;
5+
import lombok.SneakyThrows;
56
import lombok.extern.slf4j.Slf4j;
67
import org.springframework.core.io.ClassPathResource;
7-
import org.springframework.http.MediaType;
8+
import org.springframework.http.ResponseEntity;
89
import org.springframework.stereotype.Controller;
910
import org.springframework.util.FileCopyUtils;
1011
import org.springframework.web.bind.annotation.GetMapping;
@@ -34,23 +35,18 @@ public String handleSearch(HttpServletRequest request, HttpServletResponse respo
3435
return renderFileData(relativePath, response);
3536
}
3637

37-
@GetMapping({"/ui/docs/*.data", "/ui/*.data"})
38-
@ResponseBody
39-
public String handleDataFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
40-
String fullPath = request.getRequestURI().replace(request.getContextPath(), "");
41-
String relativePath = fullPath.substring(4);
42-
return renderFileData(relativePath, response);
43-
}
44-
45-
4638
@GetMapping("/ui/**")
47-
public String handleHtmlView(HttpServletRequest request) {
39+
@SneakyThrows
40+
public Object handleView(HttpServletRequest request, HttpServletResponse response) {
4841
String fullPath = request.getRequestURI().replace(request.getContextPath(), "");
4942
if ("/ui".equals(fullPath) || "/ui/".equals(fullPath)) {
5043
return "index";
5144
}
52-
String viewPath = fullPath.substring(4);
53-
return viewPath + "/index";
45+
String docPath = fullPath.substring(4);
46+
if (docPath.endsWith(".data")) {
47+
return ResponseEntity.ok(renderFileData(docPath, response));
48+
}
49+
return docPath + "/index";
5450
}
5551

5652
private String renderFileData(String relativePath, HttpServletResponse response) {
@@ -61,8 +57,6 @@ private String renderFileData(String relativePath, HttpServletResponse response)
6157
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
6258
return "File not found: " + relativePath;
6359
}
64-
response.setContentType(MediaType.TEXT_PLAIN_VALUE);
65-
response.setCharacterEncoding("UTF-8");
6660
InputStreamReader reader = new InputStreamReader(
6761
resource.getInputStream(),
6862
StandardCharsets.UTF_8

0 commit comments

Comments
 (0)