发表文章的页面 发布文章
发布文章_@autowired private iarticleservice articleserviceimpl;的articleserviceimpl报
// 发布文章
public void publish(Article article);
2.在其实现类中实现该方法
// 发布文章
@Override
public void publish(Article article) {
// 去除表情
article.setContent(EmojiParser.parseToAliases(article.getContent()));
article.setCreated(new Date());
article.setHits(0);
article.setCommentsNum(0);
// 插入文章,同时插入文章统计数据
articleMapper.publishArticle(article);
statisticMapper.addStatistic(article);
}
二、请求处理层实现
系统后台管理控制类,在类中新增向文章发布页面跳转和发布文章的请求处理方法,同时添加文章发布处理成功后跳转到文章管理列表的方法。
@Autowired private IArticleService articleServiceImpl; // 向文章发表页面跳转 @GetMapping(value = "/article/toEditPage") public String newArticle( ) { return "back/article_edit"; } // 发表文章 @PostMapping(value = "/article/publish") @ResponseBody public ArticleResponseData publishArticle(Article article) { if (StringUtils.isBlank(article.getCategories())) { article.setCategories("默认分类"); } try { articleServiceImpl.publish(article); logger.info("文章发布成功"); return ArticleResponseData.ok(); } catch (Exception e) { logger.error("文章发布失败,错误信息: "+e.getMessage()); return ArticleResponseData.fail(); } } // 跳转到后台文章列表页面 @GetMapping(value = "/article") public String index(@RequestParam(value = "page", defaultValue = "1") int page, @RequestParam(value = "count", defaultValue = "10") int count, HttpServletRequest request) { PageInfo
pageInfo = articleServiceImpl.selectArticleWithPage(page, count); request.setAttribute("articles", pageInfo); return "back/article_list"; }
三、实现前端页面功能
back文件夹下的文章发布编辑页面.html进行文章的编辑展示和发布实现
#tags_tagsinput {
background-color: #fafafa;
border: 1px solid #eeeeee;
}
#tags_addTag input {
width: 100%;
}
#tags_addTag {
margin-top: -5px;
}
.mditor .editor{
font-size: 14px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
.mditor .backdrop, .mditor .textarea, .mditor .viewer{
font-size: 14px;
}
.markdown-body{
font-size: 14px;
}
.note-toolbar {
text-align: center;
}
.note-editor.note-frame {
border: none;
}
.note-editor .note-toolbar {
background-color: #f5f5f5;
padding-bottom: 10px;
}
.note-toolbar .note-btn-group {
margin: 0;
}
.note-toolbar .note-btn {
border: none;
}
#articleForm #dropzone {
min-height: 200px;
background-color: #dbdde0;
line-height:200px;
margin-bottom: 10px;
}
#articleForm .dropzone {
border: 1px dashed #8662c6;
border-radius: 5px;
background: white;
}
#articleForm .dropzone .dz-message {
font-weight: 400;
}
#articleForm .dropzone .dz-message .note {
font-size: 0.8em;
font-weight: 200;
display: block;
margin-top: 1.4rem;
}
编辑文章
发布文章
注:
编辑页面提供了文章发布/修改所需要的主要参数,例如文章标题title、文章标签tags、文章内容等,同时针对于