@AuthPermission @RequestMapping("edit") public String edit(@Param("articleId") Long id, HttpServletRequest request) { if (null != id) { request.setAttribute("article", articleService.get(id)); } return "articleEdit"; }
@AuthPermission @RequestMapping("detail") public String detail(@Param("articleId") Long id, HttpServletRequest request) { if (null == id) { request.setAttribute("errMsg", "没有找到次文章!"); return "error"; } request.setAttribute("article", articleService.get(id)); return "articleDetail"; }
@AuthPermission @RequestMapping("list") public String list(HttpServletRequest request) { try { Long authorId = CommonsUtils.getUserIdFromSession(request); List<Article> list = articleService.pageList(authorId); request.setAttribute("list", list); return "articleList"; } catch (Exception e) { LOG.error("获取文章列表失败,", e); return JsonResponseUtils.badResult(e.getMessage()); } }
@AuthPermission @ResponseBody @RequestMapping("saveArticle") public String saveArticle(Article article, HttpServletRequest request) { try { String errMsg = ValidateUtils.articleValidate(article); if (errMsg != null) { return JsonResponseUtils.badResult(errMsg); } article.setAuthorId(CommonsUtils.getUserIdFromSession(request)); article.setAuthorName(CommonsUtils.getUserNameFromSession(request)); articleService.save(article); return JsonResponseUtils.ok(); } catch (Exception e) { LOG.error("保存文章失败,", e); return JsonResponseUtils.badResult(e.getMessage()); } }