java - Spring Boot 更改 URL 并破坏静态资产
问题描述
我有我试图在 url 下呈现的静态资产localhost:8080/test
我的目标是点击localhost:8080/test
并让它index.html
在资源目录中呈现页面。目前,当我这样做时,它会将 url 重定向到localhost:8080
并加载内容,然后当我刷新页面时,它会破坏“whitepage error”。我应该如何在这条路径下正确地为我的 /test url 提供静态资产?
控制器
@Controller
class Welcome {
@RequestMapping("/test")
public String greeting() {
return "index.html";
}
registry
.addResourceHandler("/**")
.addResourceLocations("classpath:/static/templates/")
.setCachePeriod(3000);
}
解决方案
推荐阅读
- spring - 春季启动异常:无法继续请求。无效属性
- dart - 在 Process.run 中检查什么来捕获错误?
- python - Flask/SQLAlchemy - 创建具有一对多关系的模型时出错(一个或多个映射器无法初始化......)
- python - 转换时间戳格式的问题
- python-3.x - Pyspark 数据框:从 csv 加载,然后删除第一行
- symfony - 带有 SameSite Cookie 的 Chrome 上的 Symfony iframe 日志记录问题
- woocommerce - 电话号码的 Woocommerce 前缀
- nomad - 如何在 Nomad 中删除/运行待处理的作业?
- dart - Dart:使用接口给出错误:“不是有效的覆盖”
- r - 如何分别计算每个gvkey的行总和?