创建一个自定义缓存的类(静态map)
实现CommandLineRunner接口,重写run方法
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import com.jxgp.modules.gpjc.service.CityService;
import com.jxgp.modules.gpjc.vo.CityTree;
import com.jxgp.modules.tb.entity.CompanyCatalogueEntity;
import com.jxgp.modules.tb.service.CompanyCatalogueService;
/**
* 自定义缓存
* */
@Component
public class StartMap implements CommandLineRunner{
@Autowired
private CityService cityService;
public static Map<String, Object> result;
/**单例模式*/
public static Map<String, Object> result(){
if(result==null) {
result=new HashMap<String,Object>();
}
return result;
}
public static Object getResult(String key) {
return result.get(key);
}
//定义一个启动加载的类方法(启动完成后自动运行)
@Override
public void run(String... args) throws Exception {
//此处调用需要执行的代码
System.out.println(" 启动.加载完成!");
}
}