springboot项目初始化时读取数据库
# 实现InitializingBean, ServletContextAware
@Service
public class ConstanstMap implements InitializingBean, ServletContextAware {
public final static Map<String, String> initConfig = new HashMap<>();
@Resource
private ContentVoMapper contentDao;
@Override
public void afterPropertiesSet() throws Exception {
}
@Override
public void setServletContext(ServletContext servletContext) {
ContentVoExample contentVoExample = new ContentVoExample();
contentVoExample.createCriteria().andTypeEqualTo(Types.PAGE.getType());
List<ContentVo> contentVos = contentDao.selectByExampleWithBLOBs(contentVoExample);
for (ContentVo contentVo : contentVos) {
initConfig.put(contentVo.getSlug(),contentVo.getTitle());
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
上次更新: 2021/02/20, 19:26:07