【发布时间】:2016-11-28 09:06:59
【问题描述】:
我用springboot + thymeleaf,可以找到模板页面,但是找不到静态的(css或js)。
application.yml:
spring:
application:
name: exe-springboot
thymeleaf:
suffix: .html
resources:
static-locations: /static/**
和控制器:
@RequestMapping("/index")
public String index() {
return "index";
}
index.html
<!DOCTYPE html>
<html>
<head>
<title>index</title>
<link rel="stylesheet" href="../static/index.css"/>
</head>
<body>
<h2>test page</h2>
<span class="test-span">hello world with css</span>
</body>
</html>
index.css
.test-span{
font-size: 20px;
color: red;
}
和浏览器:http://localhost:8080/index
hello world with css 的例外颜色应该是红色,但不是。和带有 chrome 的控制台显示 404 http://localhost:8080/static/index.css
【问题讨论】:
-
您可以在
index.html页面中尝试<link rel="stylesheet" th:href="@{/static/index.css}" />吗? -
我用
<link rel="stylesheet" th:href="@{index.css}"/>做的,不行,用<link rel="stylesheet" th:href="@{../static/index.css}"/>做的,还是不行,控制台显示404http://localhost:8080/static/index.css第二种方式。 -
只是localhost:8080/index.css。不要添加“静态”它也会给出 404 吗?
-
不是 404,但还是不行
-
当您在浏览器中查看页面的源代码并单击 时,如果您获取带有文件 index.css ('.test-span{ font-size: 20px; color: red; }' )源的页面,然后加载它并且问题出在其他地方?如果您有安全性,可能会或其他什么?
标签: spring-boot thymeleaf