/** 通过编号获取文章标题 */ @RequiresPermissions("cms:article:view") @ResponseBody @RequestMapping(value = "findByIds") public String findByIds(String ids) { List<Object[]> list = articleService.findByIds(ids); return JsonMapper.nonDefaultMapper().toJson(list); }
@ModelAttribute public Article get(@RequestParam(required = false) String id) { if (StringUtils.isNotBlank(id)) { return articleService.get(id); } else { return new Article(); } }
@RequiresPermissions("cms:article:edit") @RequestMapping(value = "save") public String save(Article article, Model model, RedirectAttributes redirectAttributes) { if (!beanValidator(model, article)) { return form(article, model); } articleService.save(article); addMessage(redirectAttributes, "保存文章'" + StringUtils.abbr(article.getTitle(), 50) + "'成功"); String categoryId = article.getCategory() != null ? article.getCategory().getId() : null; return "redirect:" + adminPath + "/cms/article/?repage&category.id=" + (categoryId != null ? categoryId : ""); }
@RequiresPermissions("cms:article:view") @RequestMapping(value = {"list", ""}) public String list( Article article, HttpServletRequest request, HttpServletResponse response, Model model) { // for (int i=0; i<10000000; i++){ // Article a = new Article(); // a.setCategory(new Category(article.getCategory().getId())); // a.setTitle("测试测试测试测试测试测试测试测试"+a.getCategory().getId()); // a.setArticleData(new ArticleData()); // a.getArticleData().setContent(a.getTitle()); // articleService.save(a); // } Page<Article> page = articleService.findPage(new Page<Article>(request, response), article, true); model.addAttribute("page", page); return "modules/cms/articleList"; }
@RequiresPermissions("cms:article:edit") @RequestMapping(value = "delete") public String delete( Article article, String categoryId, @RequestParam(required = false) Boolean isRe, RedirectAttributes redirectAttributes) { // 如果没有审核权限,则不允许删除或发布。 if (!UserUtils.getSubject().isPermitted("cms:article:audit")) { addMessage(redirectAttributes, "你没有删除或发布权限"); } articleService.delete(article, isRe); addMessage(redirectAttributes, (isRe != null && isRe ? "发布" : "删除") + "文章成功"); return "redirect:" + adminPath + "/cms/article/?repage&category.id=" + (categoryId != null ? categoryId : ""); }
/** * 获取文章列表 * * @param siteId 站点编号 * @param categoryId 分类编号 * @param number 获取数目 * @param param 预留参数,例: key1:'value1', key2:'value2' ... posid 推荐位(1:首页焦点图;2:栏目页文章推荐;) image * 文章图片(1:有图片的文章) orderBy 排序字符串 * @return */ public static List<Article> getArticleList( long siteId, long categoryId, int number, String param) { Page<Article> page = new Page<Article>(1, number, -1); Article article = new Article(new Category(categoryId, new Site(siteId))); if (StringUtils.isNotBlank(param)) { @SuppressWarnings({"rawtypes"}) Map map = JsonMapper.getInstance().fromJson("{" + param + "}", Map.class); if (new Integer(1).equals(map.get("posid")) || new Integer(2).equals(map.get("posid"))) { article.setPosid(String.valueOf(map.get("posid"))); } if (new Integer(1).equals(map.get("image"))) { article.setImage(Article.YES); } if (StringUtils.isNotBlank((String) map.get("orderBy"))) { page.setOrderBy((String) map.get("orderBy")); } } article.setDelFlag(Article.DEL_FLAG_NORMAL); page = articleService.find(page, article, false); return page.getList(); }
/** * 获取文章 * * @param id 文章编号 * @return */ public static Article getArticle(long articleId) { return articleService.get(articleId); }