@Component
public class CodeCache {
public static List<Map<String, Object>> codeMap = new ArrayList<Map<String, Object>>();
@Autowired
private IYqdwzService yqdwzService;
@PostConstruct
public void init() {
//系统启动中。。。加载codeMap
List<Yqdwz> codeList = yqdwzService.selectStateListAll();
for (Yqdwz code : codeList) {
Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("id", code.getId());
map1.put("diagram", code.getDiagram());
map1.put("subassembly", code.getSubassembly());
map1.put("title", code.getTitle());
map1.put("imgurl", code.getImgurl());
map1.put("details", code.getDetails());
map1.put("cid", code.getCid());
codeMap.add(map1);
}
System.out.println("+++"+codeMap.size());
}
@PreDestroy
public void destroy() {
//系统运行结束
}
@Scheduled(cron = "0 0 0/2 * * ?")
public void testOne() {
//每2小时执行一次缓存
init();
}
}
@Scheduled(fixedRate = 300000),@Scheduled注解可以设置定时时间