网上找了好多好多,终于找到了适配springboot3的配置,注意是springboot3
application.yml:
spring:
mvc:
static-path-pattern: /res/**
web:
resources:
static-locations: [ classpath:/static/ ]
/res/**
意味着所有以/res/
开头的请求都将被认为是请求静态资源
classpath:/static/
意味着静态资源存放在类路径下的/static/
目录中
其中,我的static文件夹的位置是:src/main/resources/static
好吧 又发现了新问题!springboot3图片上传到服务器后必须要服务器重启才可以获取到前端
解决方法:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/res/**").addResourceLocations("file:D:/importantFiles/Graduation Design 2024/MyAgric/src/main/resources/static/user/avatars/");
}
前端: