/**
* 显示内容
*/
@RequestMapping(value = "view-{categoryId}-{contentId}${urlSuffix}")
public String view(@PathVariable String categoryId, @PathVariable String contentId, Model model) {
Category category = categoryService.get(categoryId);
if (category==null){
Site site = CmsUtils.getSite(Site.defaultSiteId());
model.addAttribute("site", site);
return "error/404";
}
model.addAttribute("site", category.getSite());
if ("article".equals(category.getModule())){
// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
List<Category> categoryList = Lists.newArrayList();
if (category.getParent().getId().equals("1")){
categoryList.add(category);
}else{
categoryList = categoryService.findByParentId(category.getParent().getId(), category.getSite().getId());
}
// 获取文章内容
Article article = articleService.get(contentId);
if (article==null || !Article.DEL_FLAG_NORMAL.equals(article.getDelFlag())){
return "error/404";
}
// 文章阅读次数+1
articleService.updateHitsAddOne(contentId);
// 获取推荐文章列表
List<Object[]> relationList = articleService.findByIds(article.getArticleData().getRelation());
// 将数据传递到视图
model.addAttribute("category", article.getCategory());
model.addAttribute("categoryList", categoryList);
model.addAttribute("article", article);
model.addAttribute("relationList", relationList);
setTplModelAttribute(model, article.getCategory());
setTplModelAttribute(model, article.getViewConfig());
return "modules/cms/front/themes/"+category.getSite().getTheme()+"/"+getTpl(article);
}
return "error/404";
}