[英]Spring BOOT static resources mapping
我知道這個問題經常被問到,但是對我來說沒有任何作用。 我想訪問靜態資源,因此我有一個模板,其中加載了“ ../resources/css/style.css”。
但是,當我啟動應用程序時,瀏覽器無法訪問css文件。
我正在使用Spring Boot 1.1.9(也作為pom.xml中的父級)。
我的結構是:
pom.xml
src / main / java
src / main / resources
src / main / resources / database
src / main / resources / templates
src / main / resources / templates / index.html
src / main / resources / static
src / main / resources / static / resources
src / main / resources / static / resources / css
src / main / resources / static / resources / fonts
src / main / resources / static / resources / img
src / main / resources / static / 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";
}
}
主要:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Prototype {
public static void main(String[] args) throws Exception {
SpringApplication.run(Prototype.class, args);
}
}
我讀過springboot自動映射/ static /和/ resources文件...
您的索引是通過/
–應用程序的根目錄提供的。 這意味着您不需要樣式表路徑中的../
前綴。 嘗試改用resources/css/style.css
。 另外,您可以使用絕對路徑( /resources/css/style.css
),然后使用HTML的路徑並不重要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.