从本机上传的图片文件到系统中时,会上传不成功,所以可以写一个配置文件解决这个问题。
package com.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /* * 定位各种文件及头像地址 * */ @Configuration public class FileConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { //歌手头像地址 registry.addResourceHandler("/img/singerPic/**").addResourceLocations( "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+"img" +System.getProperty("file.separator")+"singerPic"+System.getProperty("file.separator") ); //歌曲图片地址的定位 registry.addResourceHandler("/img/songPic/**").addResourceLocations( "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+"img" +System.getProperty("file.separator")+"songPic"+System.getProperty("file.separator") ); //歌单图片地址的定位 registry.addResourceHandler("/img/songListPic/**").addResourceLocations( "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+"img" +System.getProperty("file.separator")+"songListPic"+System.getProperty("file.separator") ); //歌曲地址的定位 registry.addResourceHandler("/song/**").addResourceLocations( "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+"song"+System.getProperty("file.separator") ); //前端头像默认地址 registry.addResourceHandler("/img/**").addResourceLocations( "file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+"img"+System.getProperty("file.separator") ); } } |