1. 文件上传优化
1.1 url优化
说明: 如果需要通过网络虚拟路径访问服务器.则应该按照如下的配置实现.
- 本地磁盘路径: D:\JT-SOFT\images\2020\09\30\a.jpg
- 网络虚拟路径: http://image.jt.com\2020\09\30\a.jpg
1.2 编辑pro配置文件
1.3 完成属性的动态赋值
package com.jt.service;
import com.jt.vo.ImageVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@Service
@PropertySource("classpath:/properties/images.properties") //容器动态加载指定的配置文件
public class FileServiceImpl implements FileService{
//由于属性的值后期可能会发生变化,所以应该动态的获取属性数据. 利用pro配置文件
@Value("${image.rootDirPath}")
private String rootDirPath; // = "D:/JT-SOFT/images";
@Value("${image.urlPath}")
private String urlPath; // = "http://image.jt.com";
//1.2 准备图片的集合 包含了所有的图片类型.
private static Set<String> imageTypeSet;
static {
imageTypeSet = new HashSet<>();
imageTypeSet.add(".jpg");
imageTypeSet.add(".png");
imageTypeSet.add(".gif"