springBoot:找不到js/css文件 404
解决在templates路径下的页面无法访问static目录资源的方式:
来自:pixiv 画师( コーラ )
项目目录:
项目为:
springBoot+mybatis+freemarker整合
问题情境:
项目的ftl页面存放于templates的子目录user下,即templates/user/list.ftl
而css/js等放在了static目录下。
当ftl页面放在static目录下,不会出现js文件404找不到的情况。但是不符合目录的条理。
查过一些资料,发现大佬们的方法有点复杂,选择了thymeleaf
解决方案:
在pom.xml加入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
页面的html标签加入:xmlns:th=”http://www.thymeleaf.org”
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
引入资源的方式变为:
<link rel="stylesheet" th:href="@{/css/index.css}">
<script th:src="@{/js/jquery.js}"></script>
>>404没有出现,jquery效果显示!