您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Springboot-资源被解释为样式表,但以MIME类型text / htm传输

Springboot-资源被解释为样式表,但以MIME类型text / htm传输

使用 编写一些代码时,我遇到了完全相同的问题。使用CDN设置的CSS文件运行良好,而我static/css文件夹中的CSS文件设置返回了HTML内容

例:

<!-- This first worked fine, loading all styles -->
<link th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"
      href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7/css/bootstrap.min.css"
      rel="stylesheet" media="screen" />

<!-- This second one returned the content of an HTML - Content Type text/html -->
<link rel="stylesheet" th:href="@{/css/login/style.css}" href="/css/login/style.css" />

一段时间后,我发现使用 可以看到,本地返回的内容style.css与HTML页面之一相同。

检查指向具有该内容的HTML文件的路由,我可以意识到我在@RequestMapping配置中使用了错误属性我有@RequestMapping(name="..."),而不是@RequestMapping(path="...")

@RequestMapping(name = "/product/add", method = RequestMethod.GET)
public String add(Model model) {
    model.addAttribute("product", new Product());
    return "product/edit";
}

@RequestMapping(path = "/product/add", method = RequestMethod.GET)
public String add(Model model) {
    model.addAttribute("product", new Product());

    return "product/edit";
}

更改属性namepath所有内容均开始正确加载。

奇怪的是,这样的小错误如何影响了我的整个程序。

希望它对面临同样问题的人有所帮助。

Java 2022/1/1 18:14:22 有487人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶