Service 方法
public List> handleMultipartRequest(String fileGuid, MultipartRequest request, HttpServletRequest httpServletRequest) throws Exception {
List> uploadFileList=new ArrayList>();
Set>> params = request.getMultiFileMap().entrySet();
if(StringUtils.isEmpty(fileGuid)) {
fileGuid=guidGeneratorUtil.getUUID();
}
for(Entry> param : params) {
for(MultipartFile file: param.getValue()) {
if(StringUtils.isEmpty(file.getOriginalFilename())) {
logger.info("key=uploadfile File OriginalFilename is Empty.");
continue;
}
Map fileMap= handleMultipartFile(file);
fileMap.put("FileGuid", fileGuid);
fileUploadDataDao.insertFileUploadData(fileMap);
uploadFileList.add(fileMap);
}
}
return uploadFileList;
}

public Map handleMultipartFile(MultipartFile file) throws Exception{
    Map rMap=new HashMap<>();
    String msg = null;
    String extensionName=getExtensionName(file.getOriginalFilename());
    if(!checkFileExtensionName(extensionName)) {
         msg = String.format("key=uploadfile FileExtensionName:%s 文件后缀错误", extensionName);
        //logger.error(msg);
        throw new Exception(msg);
    }
    String fileId=guidGeneratorUtil.getFileId();
    rMap.put("FileId", fileId);
    StringBuilder fileSB=new StringBuilder();
    DateFormat dFormat=new SimpleDateFormat("yyyyMMdd");
    Date date =new Date();
    fileSB.append(uploadPath+dFormat.format(date));
    File destParnetFile=new File(fileSB.toString());
    if(!destParnetFile.exists()) {
        destParnetFile.mkdirs();  //如果目录不存在,则创建
    }
    File dest=new File(fileSB.toString(), fileId);
    try {
        file.transferTo(dest);  //保存文件到本地磁盘
    } catch (IllegalStateException | IOException e) {
        msg=String.format("key=uploadfile %s", e.getMessage());
        //logger.error(msg);
        throw new Exception(msg); 
    }
    rMap.put("FilePath", fileSB.toString());
    rMap.put("FileName", file.getOriginalFilename());
    rMap.put("FileType", extensionName);
    rMap.put("FileSize", file.getSize());
    return rMap;

}

/**
 * @param fileName
 * @return
 */
public String getExtensionName(String fileName) {
    String extensionName="";
    if(StringUtils.isEmpty(fileName)) {
        return extensionName;
    }
    int startIndex=fileName.indexOf(".");
    extensionName=fileName.substring(startIndex+1);
    return extensionName;
}

/**
 * @param extensionName 文件扩展名称
 * @return  返回true可以上传,返回false不可以上传
 */
private Boolean checkFileExtensionName(String extensionName) {
    boolean flag=false;  
    if(StringUtils.isEmpty(extensionName)) {
        return flag;
    }
    String[] appExtArr=StringUtils.tokenizeToStringArray(appExtStr, ",");
    for (String m : appExtArr) {
        if(extensionName.equals(m)) {
            flag=true;
            break;
        }
    }

    return flag;
}

public List>  getFileUploadDataList(Map map){
    List> rList = new ArrayList<>();
    rList=fileUploadDataDao.getFileUploadDataList(map);
    return rList;
}

public int  getFileUploadDataListCnt(Map map) {
    int result=0;
    result = fileUploadDataDao.getFileUploadDataListCnt(map);
    return result;
}

public File getUploadFile(Map map) throws Exception {
    Map fileMap= fileUploadDataDao.getFileUploadData(map).get(0);
    if(fileMap == null || fileMap.size() <=0) {
        throw new Exception("file data does not exist.");
    }
    StringBuilder sb = new StringBuilder();
    sb.append(fileMap.get("FilePath"));
    sb.append("/");
    sb.append(fileMap.get("FileId"));
    return new File(sb.toString());

}

SQL脚本


    
        select
        @@IDENTITY as id
    
    INSERT INTO [dbo].[AA_FileUploadData]
    ([FileGuid]
    ,[FileId]
    ,[FilePath]
    ,[FileName]
    ,[FileType]
    ,[FileSize]
    ,[CreateTime])
    VALUES
    (
    #{FileGuid},
    #{FileId},
    #{FilePath},
    #{FileName},
    #{FileType},
    #{FileSize},
    GetDate()
    )

分页抽象

;



    SELECT * FROM (
    SELECT ROWNUM AS "ROWNUMBER" , AA.* FROM (



    ) AA ) AAA
     = #{firstRowIndex} AND  AAA.ROWNUMBER  <= #{lastRowIndex}
     ]]>



    SELECT FLOOR((AA.totalCount-1)/#{rowPerPage})+1 totalPage , AA.* FROM (
    SELECT COUNT(*) OVER() totalCount, ROWNUM ROWNUMBER,MAINSQL.* FROM
    (




    ) MAINSQL 
     =((#{pageNo}-1)*#{rowPerPage})+1 AND ROWNUMBER <= (((#{pageNo}-1)*#{rowPerPage})+1) + #{rowPerPage}-1 ]]>

br/>固定字符串注解
@Value("${file.extension.approve.list}")
private String appExtStr;
configuration.properties 属性文件
file.extension.approve.list=dat,doc,docx,xlsx,xls,ppt,pptx,txt,gif,jpg,png,pdf,bmp,zip
file.upload.path.localhost=F:/sprout/upload/
applicationContent.xml文件引入属性文件配置

location="classpath:META-INF/properties/*.properties" />