个人记录:静态工具类中使用注解注入service_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 个人记录:静态工具类中使用注解注入service

个人记录:静态工具类中使用注解注入service

 2017/11/30 13:04:41  labybreath  程序员俱乐部  我要评论(0)
  • 摘要:packagecom.csair.hr.utils.File;importjava.util.Arrays;importjava.util.List;importjavax.annotation.PostConstruct;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Component;importcom.csair.hr.service
  • 标签:Service 使用 工具 注解 个人
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;
    	
    }
 
}
	
发表评论
用户名: 匿名