修改bug#40461
This commit is contained in:
+5
@@ -3,6 +3,7 @@ package com.jero.common.system.base.controller;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@@ -134,6 +135,10 @@ public class JeroController<T, S extends IService<T>> {
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
// 校验文件是否为excel
|
||||
if(!ImportExcelUtil.checkExcelFile(file)){
|
||||
throw new JeroBootException("请导入excel文件!");
|
||||
}
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
|
||||
+20
@@ -6,11 +6,14 @@ import com.jero.common.exception.JeroBootException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.management.remote.JMXProviderException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 导出返回信息
|
||||
@@ -91,4 +94,21 @@ public class ImportExcelUtil {
|
||||
}
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description 校验文件是否为excel
|
||||
* @Author lqt
|
||||
* @Date 2021/10/12
|
||||
* @Param file 文件对象
|
||||
* @Return
|
||||
* @Exception
|
||||
*/
|
||||
public static boolean checkExcelFile(MultipartFile file){
|
||||
if(Objects.isNull(file)){
|
||||
return false;
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
return Arrays.asList("xls","xlsx","XLS","XLSX").contains(extension);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user