中软国际实训八:SpringBoot项目——主页信息展示+详情页
1.项目结构更新
2.新闻首页与详情页
2.1 更新方法类与实现
NewService
//主页显示新闻列表
Page<News> listNew(Pageable pageable);
//主页推荐最新新闻列表
List<News> listRecommendNewTop(Integer size);
//全局搜索
Page<News> listNew(String query,Pageable pageable);
News getAndConvert(Long id);
NewServiceImpl
@Override
public Page<News> listNew(Pageable pageable) {
return newRepository.findAll(pageable);
}
@Override
public List<News> listRecommendNewTop(Integer size) {
Sort sort = Sort.by(Sort.Direction.DESC,"updateTime");
Pageable pageable = PageRequest.of(0,size,sort);
return newRepository.findTop(pageable);
}
@Override
public Page<News> listNew(String query, Pageable pageable) {
return newRepository.findByQuery(query,pageable);
}
@Override
public News getAndConvert(Long id) {
News news = newRepository.findById(id).orElse(null);
if (news==null){
System.out.println("该新闻不存在");
}
News news1 = new News();
BeanUtils.copyProperties(news,news1);
String content = news1.getContent();
news1.setContent(MarkdownUtils.markdownToHtmlExtensions(content));
return news1;
}
TagService
List<Tag> listTag(String ids);
List<Tag> listTagTop(Integer size