springboot前端页面不显示图片,css、js文件引入不起作用

1.引用地址要对
因为Springboot默认静态资源路径为static
故引用地址时不需要加static/…
正确的:

2.在application.yml中添加

spring:
  resources:
    static-locations:  classpath:/templates/,classpath:/static/,classpath:/view/,classpath:/public,classpath:/resources,classpath:/META-INF/resources
server:
  port: 1008      #当前应用运行端口号
  thymeleaf:
    prefix: classpath:/templates/ ,classpath:/static/ #prefix:指定模板所在的目录
    check-template-location: true  #check-tempate-location: 检查模板路径是否存在
    cache: false  #cache: 是否缓存,开发模式下设置为false,避免改了模板还要重启服务器,线上设置为true,可以提高性能。
    suffix:  .html
    #encoding: UTF-8
    #content-type: text/html
    mode: HTML5

3.运行http://localhost:1008/hello.html测试时(hello在templates包下),fn+f12调试时出现404,查看控制台
出现Spring boot No mapping for GET错误

Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7937e82f]
2019-05-30 12:59:48.331  WARN 16100 --- [nio-8081-exec-9] o.s.web.servlet.PageNotFound             : No mapping for GET /chem/grids.html
2019-05-30 12:59:51.241  WARN 16100 --- [io-8081-exec-10] o.s.web.servlet.PageNotFound             : No mapping for GET /chem/role.html
2019-05-30 12:59:53.512  WARN 16100 --- [nio-8081-exec-1] o.s.web.servlet.PageNotFound  

发现端口占用
打开cmd,
查看占用端口的进程:netstat -ano |findstr “1008”
根据进程号为16100,可知占用端口的程序 ***.exe:tasklist | findstr “16100”
关闭进程号为16100的进程——
:taskkill /f /pid 16100 (根据进程号关闭进程)
:taskkill /f /im ***.exe(根据程序名关闭进程)
4.重启项目,成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值