* 内容列表
*/
@RequestMapping(value = "list-{categoryId}${urlSuffix}")
public String list(@PathVariable String categoryId, @RequestParam(required=false, defaultValue="1") Integer pageNo,
@RequestParam(required=false, defaultValue="15") Integer pageSize, 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());
// 2:简介类栏目,栏目第一条内容
if("2".equals(category.getShowModes()) && "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());
}
model.addAttribute("category", category);
model.addAttribute("categoryList", categoryList);
// 获取文章内容
Page<Article> page = new Page<Article>(1, 1, -1);
Article article = new Article(category);
page = articleService.find(page, article, false);
if (page.getList().size()>0){
article = page.getList().get(0);
articleService.updateHitsAddOne(article.getId());
}
model.addAttribute("article", article);
setTplModelAttribute(model, category);
setTplModelAttribute(model, article.getViewConfig());
return "modules/cms/front/themes/"+category.getSite().getTheme()+"/"+getTpl(article);
}else{
List<Category> categoryList = categoryService.findByParentId(category.getId(), category.getSite().getId());
// 展现方式为1 、无子栏目或公共模型,显示栏目内容列表
if("1".equals(category.getShowModes())||categoryList.size()==0){
// 有子栏目并展现方式为1,则获取第一个子栏目;无子栏目,则获取同级分类列表。
if(categoryList.size()>0){
category = categoryList.get(0);
}else{
// 如果没有子栏目,并父节点为跟节点的,栏目列表为当前栏目。
if (category.getParent().getId().equals("1")){
categoryList.add(category);
}else{
categoryList = categoryService.findByParentId(category.getParent().getId(), category.getSite().getId());
}
}
model.addAttribute("category", category);
model.addAttribute("categoryList", categoryList);
// 获取内容列表
if ("article".equals(category.getModule())){
Page<Article> page = new Page<Article>(pageNo, pageSize);
page = articleService.find(page, new Article(category), false);
model.addAttribute("page", page);
// 如果第一个子栏目为简介类栏目,则获取该栏目第一篇文章
if ("2".equals(category.getShowModes())){
Article article = new Article(category);
if (page.getList().size()>0){
article = page.getList().get(0);
articleService.updateHitsAddOne(article.getId());
}
model.addAttribute("article", article);
setTplModelAttribute(model, category);
setTplModelAttribute(model, article.getViewConfig());
return "modules/cms/front/themes/"+category.getSite().getTheme()+"/"+getTpl(article);
}
}else if ("link".equals(category.getModule())){
Page<Link> page = new Page<Link>(1, -1);
page = linkService.find(page, new Link(category), false);
model.addAttribute("page", page);
}
String view = "/frontList";
if (StringUtils.isNotBlank(category.getCustomListView())){
view = "/"+category.getCustomListView();
}
setTplModelAttribute(model, category);
return "modules/cms/front/themes/"+category.getSite().getTheme()+view;
}
// 有子栏目:显示子栏目列表
else{
model.addAttribute("category", category);
model.addAttribute("categoryList", categoryList);
String view = "/frontListCategory";
if (StringUtils.isNotBlank(category.getCustomListView())){
view = "/"+category.getCustomListView();
}
setTplModelAttribute(model, category);
return "modules/cms/front/themes/"+category.getSite().getTheme()+view;
}
}
}