需求:启动项目把某些高频搜索的数据,放入到缓存中;
现象:利用@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: 了解其原理:
标签:插件,title,PostConstruct,PageHelper,researchInformationTitle,researchInformationDT From: https://www.cnblogs.com/zyd-2020/p/18220208