第一种方式 : 放在src/main/webapp目录下
放在webapp目录下的静态资源是可以直接访问的
user.html
2.png
在user.html中引用2.png
第二种方式:放在classpath下
ResourcePRoperties中的说明
org.springframework.boot.autoconfigure.web.ResourceProperties
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" };静态资源默认放在classpath路径下:Defaults to classpath:[/META-INF/resources/,/resources/, /static/, /public/] plus context:/ (the root of the servlet context).
person/index.html
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title><link href="/CSS/main.css" rel="stylesheet" type="text/css"/><script type="text/javascript" src="/js/main.js"></script><script type="text/Javascript"> sayHello();</script></head><body> <h3>person page HTML</h3></body></html>通过修改配置项,设置静态资源的位置
application.properties
# 修改默认的静态资源存放目录spring.resources.static-locations=classpath:/web/新闻热点
疑难解答