【问题标题】:nested mapping in Spring Boot does not load static contentSpring Boot 中的嵌套映射不加载静态内容
【发布时间】:2020-01-26 21:14:36
【问题描述】:

所以这是我的 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>

这是我的控制器:

    @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(浏览器选项卡中的徽标),所以我尝试了一切,最后写了测试映射:

    @GetMapping("test")
    public String showGetPass(){
        return "getPass";
    }

localhost:8080/test 一切正常,我的意思是徽标出现在浏览器选项卡中,样式来自 .css

所以我的快速解决方案是我将所有 .css 文件打包在 getPass.html 中的 &lt;style&gt;&lt;/style&gt; 标记中......但我很想知道:

将 UUID 作为获取请求的 URL 端点有什么问题吗?我的意思是,在 html 文件中链接 css 文件是否有问题?

更新: 当我在 @RequestMapping 中删除 password/link/ 时它正在工作,但是 xzy/jkj/{id} 有什么问题?

【问题讨论】:

    标签: java css spring-mvc uuid get-request


    【解决方案1】:

    解决了!

    我唯一需要的是/!!!!在 css 后面:th:href="@{css/style.css}" 所以th:href="@{/css/style.css}"

    到底为什么@GetMapping("xxx")@GetMapping("nested/xxx")之间会有所不同... !!!!

    【讨论】:

      猜你喜欢
      • 2017-04-05
      • 2017-02-21
      • 2017-03-25
      • 2017-07-19
      • 2016-12-24
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      相关资源
      最近更新 更多