javascript - 由于 URL 文本,spring boot thymeleaf 找不到资源

标签 javascript java spring spring-boot thymeleaf

当重定向到不同的 url(错误页面)时,我的 spring boot Controller url 无法找到静态资源(css、js 等)

Controller 网址:http://localhost:8080/document/ {someId} 重定向 URL:错误页面

当我的 Controller 出现错误时,我会将页面重定向到错误页面。

由于当我将页面重定向到错误页面时 Controller URL 包含“/document”,资源未加载。我在控制台中查找并看到以下 url 的 404 问题:

http://localhost:8080/document/styles.css
http://localhost:8080/document/newstyles.css
http://localhost:8080/document/bootstrap.js

所以我看到这里的“/document”这个词导致了这个问题。

所以我的问题是:有没有办法从 URL 中删除/document?谢谢

最佳答案

您的错误页面 Thymeleaf 模板必须使用 @{xxx} 来构建指向 .css.js 文件的 URL,因为您不知道基本 URL。

参见 4.4 Link URLs 部分在 Thymeleaf 文档中,

关于javascript - 由于 URL 文本,spring boot thymeleaf 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56015213/

相关文章:

在构造函数中使用@ConfigurationProperties 和@Value 的Spring 前缀

java - 如何在 Heroku 中运行 Spring Boot WAR 应用程序?

javascript - 读取 Canvas 像素的 RGB 值

javascript - setTimeout() 方法中的 clearTimeout() 在 JS 中不起作用

java - 如何使 JTable 在 Java 中可编辑

java - 具有正确端点的 Android BulkTransfer 没有响应

javascript - Angular-js 过滤器查找空字符串

javascript - pentaho mysql 日期时间 javascript 比较

java - 无需连接到互联网即可获取本地 IP 地址

Javax 验证不适用于值为数组或列表的 Hashmap