class="java" name="code"> package com.csair.hr.utils.File; import java.util.Arrays; import java.util.List; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.csair.hr.service.systemManage.SetTemplateService; import com.csair.hr.vo.systemManage.TemplateVO; @Component public class FileUtil { @Autowired private SetTemplateService setTemplateService; private static FileUtil fileUtil; public void setSetTemplateService(SetTemplateService setTemplateService) { this.setTemplateService = setTemplateService; } @PostConstruct public void init() { fileUtil = this; fileUtil.setTemplateService = this.setTemplateService; // 初使化时将已静态化的testService实例化 } public static boolean isLegalFileType(String fileName){ //String[] allowTypeArr = { "xls", "xlsx","txt","doc","docx","rar","ppt","zip" }; TemplateVO templateVO = new TemplateVO(); templateVO = fileUtil.setTemplateService.findTemplateByName("附件类型白名单"); String[] allowTypeArr; if(templateVO!=null){ String allowType = templateVO.getTemplateContent(); allowTypeArr = allowType.split(";"); }else{ allowTypeArr = new String[]{ "xls", "xlsx","txt","doc","docx","rar","ppt","zip" }; } List<String> allowTypes = Arrays.asList(allowTypeArr); if(null!=fileName){ String fileType=fileName.substring(fileName.lastIndexOf('.')+1,fileName.length()); if(allowTypes.contains(fileType)){ return true; } } return false; } }