SpringBoot+thymeleaf项目,controller路径跳转页面无法引入js+css的问题解决

Ps:如果页面出不来效果,F12出现“jquery.js:1 Failed to load resource: the server responded with a status of 404 ()“等报错,那就是没有引入外部js,css的错啦。

话不多说直接上解决方案:
1.检查是否加了依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2.application.properties是否加了配置:

#thymelea模板配置
spring.thymeleaf.prefix=classpath:/templates/
# templates中的所有文件后缀名
spring.thymeleaf.suffix=.html
#spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false
#spring.resources.chain.strategy.content.enabled=true
#spring.resources.chain.strategy.content.paths=/**

3.检查.html文件是否放在了resource–>templates文件夹路径下,以及css,js等的外部包是否放在了resource–>static文件夹路径下。

4.。html文件里引入方式为:

<script th:src="@{/js/jquery.js}"  type="text/javascript"></script>

从static位置后开始写,如果想静态编辑一起引入,可以:

<script th:src="@{/js/jquery.js}" src="../static/js/jquery.js" type="text/javascript"></script>

over.打完收工。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值