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.重启项目,成功!

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐