文章目录
前端都是一个input类型file
1、不打jar包上传图片
String parent = this.getClass().getClassLoader().getResource("static").getFile()+"/images";
生成文件路径,上传的图片会在target目录下的static/images中,默认静态资源访问路径就是这里,可以直接通过外链访问
2、打成jar包部署后上传图片
打成jar包后,你只能读打包以前的图片,也无法保存到里面,这时候需要在其他地方保存图片,
存到jar包同级目录下的static中,然修改application.properties,添加静态资源目录路径映射
File path = new File(ResourceUtils.getURL("classpath:").getPath());
if(!path.exists()) {
path = new File("");
}
File upload = new File(path.getAbsolutePath(),"static/images/");
if(!upload.exists()) {
upload.mkdirs();
}
String parent= upload.getPath()