使用 编写一些代码时,我遇到了完全相同的问题。使用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";
}
奇怪的是,这样的小错误如何影响了我的整个程序。
希望它对面临同样问题的人有所帮助。