这是我的 html 文件:
getPass.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" type="image/jpg" href="../static/image/PUB_PIX_LION_K.jpg"
th:href="@{image/PUB_PIX_LION_K.jpg}">
<link href="../static/css/style.css" th:href="@{css/style.css}" rel="stylesheet" media="screen"/>
<title>PP-Secure</title>
</head>
<body>
<div class="wrapper-notification">
<h3>Password:</h3>
<p th:text="${dispPass}"></p>
<p th:text="${dispError}"></p>
</div>
</body>
</html>
这是我的 Controller :
@RequestMapping("password/link/{enterId}")
public ModelAndView getPasswordById(@PathVariable("enterId") UUID uuid) {
ModelAndView mv = new ModelAndView();
if(passwordService.hasKey(uuid)) {
String passText = passwordService.getPassTextById(uuid).getPassText();
mv.addObject("dispPass",passText);
mv.setViewName("getPass");
} else {
String error = "No password available.";
mv.addObject("dispError",error);
mv.setViewName("getPass");
}
passwordService.removePasswordAfterVisit(uuid);
return mv;
}
问题是当我使用这个URL(上面的@RequestMapping()的参数)时,html页面既不使用.css(样式)也不使用.jpg(浏览器选项卡中的 Logo ),所以我尝试了一切,最后写了测试映射:
@GetMapping("test")
public String showGetPass(){
return "getPass";
}
localhost:8080/test 一切正常,我的意思是 Logo 出现在浏览器选项卡中,样式来自 .css
所以我的快速解决方案是我将所有 .css 文件打包在 <style></style>
中getPass.html 中的标签...但我很想知道:
将 UUID 作为 Get 请求的 URL 端点是否有任何问题?我的意思是,在 html 文件中链接 css 文件会产生问题吗?
更新:
当我删除 password/link/
时它正在工作在@RequestMapping
但是 xzy/jkj/{id} 有什么问题吗?
最佳答案
解决了!
我唯一需要的是一个/
!!!! css 后面: th:href="@{css/style.css}"
所以 th:href="@{/css/style.css}"
到底为什么@GetMapping("xxx")
和@GetMapping("nested/xxx")
之间有区别...!!!!
关于java - Spring Boot 中的嵌套映射不加载静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58119386/