@PostConstruct 注解方法 mybatis-plus分页插件 PageHelper失效

需求:启动项目把某些高频搜索的数据,放入到缓存中;

现象:利用@PostConstruct 项目启动加载,但是并没有做到分页,而是降所有数据放入的redis中,出现问题

 

@PostConstruct 注解方法 mybatis-plus分页插件 PageHelper失效

@PostConstruct
public void init() {
        long keyStartTime = System.currentTimeMillis();
        log.info("========================== 项目启动,更新缓存数据  start =============================>>>>>>");
        syncRedisData(true);
        log.info("========================== 项目启动,更新缓存数据  end =============================>>>>>>");
        long keyEndTime = System.currentTimeMillis();
        log.info("项目启动,更新缓存数据,耗时 ------>>>>>> , {} 毫秒" , (keyEndTime-keyStartTime));
}
public void syncRedisData(boolean initFlag) {
  pageListResearchInformation(...);
}
public R<List<ResearchInformationTitle>> pageListResearchInformation(
ResearchInformationDTO researchInformationDTO) {
// TODO Auto-generated method stub
Page<Object> questionPage = PageHelper.startPage(researchInformationDTO.getPageNum(),
researchInformationDTO.getPageSize());
List<ResearchInformationTitle> list = researchInformationMapper.listResearchInformation(researchInformationDTO);
for (ResearchInformationTitle researchInformationTitle : list) {
// 文件 加全路径
if (researchInformationTitle.getFile1() != null
&& researchInformationTitle.getFile1().indexOf(ResearchInformationConstants.FILE_FORMAT_STR) >= 0) {
researchInformationTitle
.setFile1(ResearchInformationConstants.FZ_WEB_SITE_ADDR + researchInformationTitle.getFile1());
}
// title 转义
String title = researchInformationTitle.getTitle();
if (org.apache.commons.lang3.StringUtils.isNotEmpty(title)) {
researchInformationTitle.setTitle(HtmlUtils.htmlUnescape(title));
}
}
R<List<ResearchInformationTitle>> ok = R.ok(list, questionPage.getTotal());
return ok;
}

todo: 了解其原理:

 

posted @ 2024-05-29 14:27  yingdong2019  阅读(76)  评论(0)    收藏  举报