当重定向到不同的 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/