spring boot默认加载文件的路径是
/META-INF/resources/
/resources/
/static/
/public/
这些目录下面, 当然我们也可以从spring boot源码也可以看到
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" };
模板:
<!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <title>Getting Started: Serving Web Content</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script type="text/javascript" th:src="@{/jquery-1.10.2.min.js}"></script> </head> <body> <p th:text="'Hello, ' + ${name} + '!'" /> <p th:text="'Hello, ' + ${customers} + '!'" /> <table> <tr> <th>NAME</th> <th>PRICE</th> <th>IN STOCK</th> </tr> <tr th:each="customer, iterStat : ${customers}"> <td th:text="${customer.id}">Onions</td> <td th:text="${customer.firstName}">2.41</td> <td th:text="${customer.lastName}">yes</td> </tr> </table> </body> </html>
src 文件位置:
/spring-mvc/src/main/resources/static/jquery-1.10.2.min.js
target文件位置:
/spring-mvc/target/classes/static/jquery-1.10.2.min.js
浏览器加载
http://localhost:8080/jquery-1.10.2.min.js
加载原理: resources目录下的静态资源会被编译至target/classess/下, 系统根据预定目录查找
优先级顺序为:META/resources > resources > static > public
http://blog.webinno.cn/article/view/141本文地址:http://blog.webinno.cn/article/view/141
版权声明:本站博客内所有原创文章及原创翻译转载需经作者同意,否则不得转载!其他文章可自由转载!
转载本站文章需注明本出处,并请注明原出处,尊重作者和版权!
发表于 @ 2016年03月17日 | 浏览2526次| 编辑 |评论(loading... ) |
评论列表