我知道这个问题经常问,但对我没什么用。我想访问静态资源,因此我有一个加载“./ resources /css/style.css”的模板。
但是当我启动应用程序时,浏览器无法访问css文件。
我正在使用SpringBoot1.1.9(也是pom.xml中的父级)。
我的结构是:
pom.xml src/main/java src/主要/资源 src/main/resources/数据库 src/主/资源/模板 src/main/resources/templates/index.html src/主/资源/静态 src/主/资源/静态/资源 src/main/resources/static/resources/css src/主/资源/静态/资源/字体 src/main/resources/static/resources/img src/main/resources/静态/resources/js
(见http://i62.tinypic.com/of84jt.png)
我的财务主任:
package prototype.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class IndexController {
@RequestMapping("/")
public String stdRedirect(){
return "redirect:/index";
}
@RequestMapping(value="/index", method=RequestMethod.GET)
public String index(){
return "index";
}
}Main:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Prototype {
public static void main(String[] args) throws Exception {
SpringApplication.run(Prototype.class, args);
}
} 我读过跳转自动地图/静态/和/resources文件..。
发布于 2014-11-12 19:09:53
您的索引是从/提供的--应用程序的根。这意味着您不需要样式表路径上的../前缀。尝试使用resources/css/style.css代替。或者,您可以使用一个绝对路径(/resources/css/style.css),那么什么路径为HTML服务并不重要。
https://stackoverflow.com/questions/26891186
复制相似问题