👽 代码优化

pull/21/head
ruibaby 2018-07-15 11:51:38 +08:00
parent 99e204fb18
commit b7d7e9fa1c
40 changed files with 215 additions and 185 deletions

View File

@ -94,6 +94,7 @@ public interface PostService {
/** /**
* *
*
* @param pageable pageable * @param pageable pageable
* @return Page * @return Page
*/ */

View File

@ -20,11 +20,11 @@ import java.util.Optional;
@Service @Service
public class AttachmentServiceImpl implements AttachmentService { public class AttachmentServiceImpl implements AttachmentService {
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
@Autowired @Autowired
private AttachmentRepository attachmentRepository; private AttachmentRepository attachmentRepository;
private static final String ATTACHMENTS_CACHE_NAME = "attachments";
/** /**
* *
* *

View File

@ -22,11 +22,11 @@ import java.util.Optional;
@Service @Service
public class CommentServiceImpl implements CommentService { public class CommentServiceImpl implements CommentService {
private static final String COMMENTS_CACHE_NAME = "comments";
@Autowired @Autowired
private CommentRepository commentRepository; private CommentRepository commentRepository;
private static final String COMMENTS_CACHE_NAME = "comments";
/** /**
* *
* *

View File

@ -20,11 +20,11 @@ import java.util.Optional;
@Service @Service
public class GalleryServiceImpl implements GalleryService { public class GalleryServiceImpl implements GalleryService {
private static final String GALLERIES_CACHE_NAME = "galleries";
@Autowired @Autowired
private GalleryRepository galleryRepository; private GalleryRepository galleryRepository;
private static final String GALLERIES_CACHE_NAME = "galleries";
/** /**
* *
* *

View File

@ -18,13 +18,13 @@ import java.util.Optional;
@Service @Service
public class LinkServiceImpl implements LinkService { public class LinkServiceImpl implements LinkService {
@Autowired
private LinkRepository linkRepository;
private static final String LINKS_CACHE_KEY = "'link'"; private static final String LINKS_CACHE_KEY = "'link'";
private static final String LINKS_CACHE_NAME = "links"; private static final String LINKS_CACHE_NAME = "links";
@Autowired
private LinkRepository linkRepository;
/** /**
* / * /
* *

View File

@ -18,13 +18,13 @@ import java.util.Optional;
@Service @Service
public class MenuServiceImpl implements MenuService { public class MenuServiceImpl implements MenuService {
@Autowired
private MenuRepository menuRepository;
private static final String MENUS_CACHE_KEY = "'menu'"; private static final String MENUS_CACHE_KEY = "'menu'";
private static final String MENUS_CACHE_NAME = "menus"; private static final String MENUS_CACHE_NAME = "menus";
@Autowired
private MenuRepository menuRepository;
/** /**
* *
* *

View File

@ -30,11 +30,11 @@ import java.util.Optional;
@Service @Service
public class PostServiceImpl implements PostService { public class PostServiceImpl implements PostService {
private static final String POSTS_CACHE_NAME = "posts";
@Autowired @Autowired
private PostRepository postRepository; private PostRepository postRepository;
private static final String POSTS_CACHE_NAME = "posts";
/** /**
* *
* *

View File

@ -215,7 +215,7 @@ public class AdminController extends BaseController {
try { try {
logsService.removeAllLogs(); logsService.removeAllLogs();
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:" + e.getMessage()); log.error("清除日志失败:{}" + e.getMessage());
} }
return "redirect:/admin"; return "redirect:/admin";
} }

View File

@ -177,7 +177,7 @@ public class AttachmentController {
result.put("message", "上传成功!"); result.put("message", "上传成功!");
result.put("url", attachment.getAttachPath()); result.put("url", attachment.getAttachPath());
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("上传文件失败:{}", e.getMessage());
e.printStackTrace(); e.printStackTrace();
result.put("success", 0); result.put("success", 0);
result.put("message", "上传失败!"); result.put("message", "上传失败!");

View File

@ -107,7 +107,7 @@ public class BackupController {
log.info("当前时间:"+DateUtil.now()+",执行了数据库备份。"); log.info("当前时间:"+DateUtil.now()+",执行了数据库备份。");
return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("备份数据库失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!"); return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!");
} }
} }
@ -130,7 +130,7 @@ public class BackupController {
log.info("当前时间:"+DateUtil.now()+",执行了资源文件备份。"); log.info("当前时间:"+DateUtil.now()+",执行了资源文件备份。");
return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("备份资源文件失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!"); return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!");
} }
} }
@ -159,7 +159,7 @@ public class BackupController {
log.info("当前时间:"+DateUtil.now()+",执行了文章备份。"); log.info("当前时间:"+DateUtil.now()+",执行了文章备份。");
return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(), "备份成功!");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("备份文章失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!"); return new JsonResult(ResultCode.FAIL.getCode(), "备份失败!");
} }
} }
@ -227,7 +227,7 @@ public class BackupController {
content.put("size", HaloUtils.parseSize(file.length())); content.put("size", HaloUtils.parseSize(file.length()));
mailService.sendAttachMail(user.getUserEmail(), "有新的备份!", content, "common/mail/mail_attach.ftl", srcPath); mailService.sendAttachMail(user.getUserEmail(), "有新的备份!", content, "common/mail/mail_attach.ftl", srcPath);
} catch (Exception e) { } catch (Exception e) {
log.error("邮件服务器未配置:", e.getMessage()); log.error("邮件服务器未配置:{}", e.getMessage());
} }
} }
} }

View File

@ -44,7 +44,7 @@ public class CategoryController {
try { try {
categoryService.saveByCategory(category); categoryService.saveByCategory(category);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误{0}", e.getMessage()); log.error("修改分类失败{0}", e.getMessage());
} }
return "redirect:/admin/category"; return "redirect:/admin/category";
} }
@ -74,7 +74,7 @@ public class CategoryController {
Category category = categoryService.removeByCateId(cateId); Category category = categoryService.removeByCateId(cateId);
log.info("删除的分类目录:" + category); log.info("删除的分类目录:" + category);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误{}", e.getMessage()); log.error("删除分类失败{}", e.getMessage());
} }
return "redirect:/admin/category"; return "redirect:/admin/category";
} }

View File

@ -17,6 +17,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator; import cn.hutool.core.lang.Validator;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.HtmlUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -92,13 +93,14 @@ public class CommentController extends BaseController {
*/ */
@GetMapping(value = "/throw") @GetMapping(value = "/throw")
public String moveToTrash(@PathParam("commentId") Long commentId, public String moveToTrash(@PathParam("commentId") Long commentId,
@PathParam("status") String status) { @PathParam("status") String status,
@RequestParam(value = "page",defaultValue = "0") Integer page) {
try { try {
commentService.updateCommentStatus(commentId, CommentStatus.RECYCLE.getCode()); commentService.updateCommentStatus(commentId, CommentStatus.RECYCLE.getCode());
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误{}", e.getMessage()); log.error("删除评论失败{}", e.getMessage());
} }
return "redirect:/admin/comments?status=" + status; return "redirect:/admin/comments?status=" + status+"&page="+page;
} }
/** /**
@ -153,13 +155,14 @@ public class CommentController extends BaseController {
*/ */
@GetMapping("/remove") @GetMapping("/remove")
public String moveToAway(@PathParam("commentId") Long commentId, public String moveToAway(@PathParam("commentId") Long commentId,
@PathParam("status") Integer status) { @PathParam("status") Integer status,
@RequestParam(value = "page",defaultValue = "0") Integer page) {
try { try {
commentService.removeByCommentId(commentId); commentService.removeByCommentId(commentId);
} catch (Exception e) { } catch (Exception e) {
log.error("删除评论失败:{}", e.getMessage()); log.error("删除评论失败:{}", e.getMessage());
} }
return "redirect:/admin/comments?status=" + status; return "redirect:/admin/comments?status=" + status+"&page="+page;
} }
@ -200,7 +203,7 @@ public class CommentController extends BaseController {
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail())); comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
comment.setCommentDate(DateUtil.date()); comment.setCommentDate(DateUtil.date());
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> "; String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
comment.setCommentContent(lastContent + OwoUtil.markToImg(commentContent)); comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.encode(commentContent)));
comment.setCommentAgent(userAgent); comment.setCommentAgent(userAgent);
comment.setCommentParent(commentId); comment.setCommentParent(commentId);
comment.setCommentStatus(CommentStatus.PUBLISHED.getCode()); comment.setCommentStatus(CommentStatus.PUBLISHED.getCode());
@ -228,7 +231,7 @@ public class CommentController extends BaseController {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("回复评论失败{}", e.getMessage()); log.error("回复评论失败{}", e.getMessage());
} }
return "redirect:/admin/comments"; return "redirect:/admin/comments";
} }

View File

@ -44,7 +44,7 @@ public class MenuController {
try { try {
menuService.saveByMenu(menu); menuService.saveByMenu(menu);
} catch (Exception e) { } catch (Exception e) {
log.error("保存菜单失败:" + e.getMessage()); log.error("保存菜单失败:{}" + e.getMessage());
} }
return "redirect:/admin/menus"; return "redirect:/admin/menus";
} }
@ -74,7 +74,7 @@ public class MenuController {
try { try {
menuService.removeByMenuId(menuId); menuService.removeByMenuId(menuId);
} catch (Exception e) { } catch (Exception e) {
log.error("删除菜单失败:{0}", e.getMessage()); log.error("删除菜单失败:{}", e.getMessage());
} }
return "redirect:/admin/menus"; return "redirect:/admin/menus";
} }

View File

@ -55,7 +55,7 @@ public class OptionController {
log.info("所保存的设置选项列表:" + options); log.info("所保存的设置选项列表:" + options);
return new JsonResult(ResultCode.SUCCESS.getCode(),"保存成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(),"保存成功!");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("保存设置选项失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"保存失败!"); return new JsonResult(ResultCode.FAIL.getCode(),"保存失败!");
} }
} }

View File

@ -99,10 +99,9 @@ public class PageController {
@PostMapping(value = "/links/save") @PostMapping(value = "/links/save")
public String saveLink(@ModelAttribute Link link) { public String saveLink(@ModelAttribute Link link) {
try { try {
Link backLink = linkService.saveByLink(link); linkService.saveByLink(link);
log.info("保存成功,数据为:" + backLink);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("保存/修改友情链接失败:{}", e.getMessage());
} }
return "redirect:/admin/page/links"; return "redirect:/admin/page/links";
} }
@ -116,10 +115,9 @@ public class PageController {
@GetMapping(value = "/links/remove") @GetMapping(value = "/links/remove")
public String removeLink(@PathParam("linkId") Long linkId) { public String removeLink(@PathParam("linkId") Long linkId) {
try { try {
Link link = linkService.removeByLinkId(linkId); linkService.removeByLinkId(linkId);
log.info("删除的友情链接:" + link);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误", e.getMessage()); log.error("删除友情链接失败", e.getMessage());
} }
return "redirect:/admin/page/links"; return "redirect:/admin/page/links";
} }
@ -180,18 +178,18 @@ public class PageController {
* *
* *
* @param galleryId * @param galleryId
* @return truefalse * @return JsonResult
*/ */
@GetMapping(value = "/gallery/remove") @GetMapping(value = "/gallery/remove")
@ResponseBody @ResponseBody
public boolean removeGallery(@RequestParam("galleryId") Long galleryId) { public JsonResult removeGallery(@RequestParam("galleryId") Long galleryId) {
try { try {
galleryService.removeByGalleryId(galleryId); galleryService.removeByGalleryId(galleryId);
} catch (Exception e) { } catch (Exception e) {
log.error("删除图片失败:{0}", e.getMessage()); log.error("删除图片失败:{}", e.getMessage());
return false; return new JsonResult(ResultCode.FAIL.getCode(), "删除失败!");
} }
return true; return new JsonResult(ResultCode.SUCCESS.getCode(), "删除成功!");
} }
@ -234,7 +232,7 @@ public class PageController {
logsService.saveByLogs(new Logs(LogsRecord.PUSH_PAGE, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date())); logsService.saveByLogs(new Logs(LogsRecord.PUSH_PAGE, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
return new JsonResult(ResultCode.SUCCESS.getCode(),msg); return new JsonResult(ResultCode.SUCCESS.getCode(),msg);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误{}", e.getMessage()); log.error("保存页面失败{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"保存失败"); return new JsonResult(ResultCode.FAIL.getCode(),"保存失败");
} }
} }
@ -257,16 +255,16 @@ public class PageController {
* *
* *
* @param postUrl postUrl * @param postUrl postUrl
* @return true or false * @return JsonResult
*/ */
@GetMapping(value = "/checkUrl") @GetMapping(value = "/checkUrl")
@ResponseBody @ResponseBody
public boolean checkUrlExists(@PathParam("postUrl") String postUrl) { public JsonResult checkUrlExists(@PathParam("postUrl") String postUrl) {
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc()); Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
// TODO 还没写完 // TODO 还没写完
if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) { if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) {
return true; return new JsonResult(ResultCode.FAIL.getCode(), "该路径已经存在!");
} }
return false; return new JsonResult(ResultCode.SUCCESS.getCode(), "");
} }
} }

View File

@ -119,7 +119,7 @@ public class PostController extends BaseController {
Pageable pageable = PageRequest.of(page, size, sort); Pageable pageable = PageRequest.of(page, size, sort);
model.addAttribute("posts", postService.searchPosts(keyword, pageable)); model.addAttribute("posts", postService.searchPosts(keyword, pageable));
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("未知错误:{}", e.getMessage());
} }
return "admin/admin_post"; return "admin/admin_post";
} }
@ -165,7 +165,7 @@ public class PostController extends BaseController {
//提取摘要 //提取摘要
int postSummary = 50; int postSummary = 50;
if (StringUtils.isNotEmpty(BlogProperties.POST_SUMMARY.getProp())) { if (StringUtils.isNotEmpty(BlogProperties.POST_SUMMARY.getProp())) {
postSummary = Integer.parseInt(BlogProperties.POST_SUMMARY.getProp()); postSummary = Integer.parseInt(HaloConst.OPTIONS.get(BlogProperties.POST_SUMMARY.getProp()));
} }
//文章摘要 //文章摘要
String summaryText = HtmlUtil.cleanHtmlTag(post.getPostContent()); String summaryText = HtmlUtil.cleanHtmlTag(post.getPostContent());
@ -198,7 +198,7 @@ public class PostController extends BaseController {
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date())); logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
return new JsonResult(ResultCode.SUCCESS.getCode(), msg); return new JsonResult(ResultCode.SUCCESS.getCode(), msg);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("保存文章失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(), "保存失败"); return new JsonResult(ResultCode.FAIL.getCode(), "保存失败");
} }
} }
@ -207,9 +207,13 @@ public class PostController extends BaseController {
/** /**
* 稿 * 稿
* *
* @param post post * @param postId
* @param postTitle
* @param postUrl
* @param postContentMd
* @param postType
* @param session session * @param session session
* @return * @return JsonResult
*/ */
@PostMapping(value = "/new/autoPush") @PostMapping(value = "/new/autoPush")
@ResponseBody @ResponseBody
@ -266,7 +270,7 @@ public class PostController extends BaseController {
postService.updatePostStatus(postId, PostStatus.RECYCLE.getCode()); postService.updatePostStatus(postId, PostStatus.RECYCLE.getCode());
log.info("编号为" + postId + "的文章已被移到回收站"); log.info("编号为" + postId + "的文章已被移到回收站");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("未知错误:{}", e.getMessage());
} }
return "redirect:/admin/posts?status=" + status; return "redirect:/admin/posts?status=" + status;
} }
@ -284,7 +288,7 @@ public class PostController extends BaseController {
postService.updatePostStatus(postId, PostStatus.PUBLISHED.getCode()); postService.updatePostStatus(postId, PostStatus.PUBLISHED.getCode());
log.info("编号为" + postId + "的文章已改变为发布状态"); log.info("编号为" + postId + "的文章已改变为发布状态");
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("未知错误:{}", e.getMessage());
} }
return "redirect:/admin/posts?status=" + status; return "redirect:/admin/posts?status=" + status;
} }
@ -302,7 +306,7 @@ public class PostController extends BaseController {
postService.removeByPostId(postId); postService.removeByPostId(postId);
logsService.saveByLogs(new Logs(LogsRecord.REMOVE_POST, post.get().getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date())); logsService.saveByLogs(new Logs(LogsRecord.REMOVE_POST, post.get().getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("未知错误:{}", e.getMessage());
} }
if (StringUtils.equals(PostType.POST_TYPE_POST.getDesc(), postType)) { if (StringUtils.equals(PostType.POST_TYPE_POST.getDesc(), postType)) {
return "redirect:/admin/posts?status=2"; return "redirect:/admin/posts?status=2";
@ -328,18 +332,19 @@ public class PostController extends BaseController {
* *
* *
* @param postSummary * @param postSummary
* @return truefalse * @return JsonResult
*/ */
@GetMapping(value = "/updateSummary") @GetMapping(value = "/updateSummary")
@ResponseBody @ResponseBody
public boolean updateSummary(@PathParam("postSummary") Integer postSummary) { public JsonResult updateSummary(@PathParam("postSummary") Integer postSummary) {
try { try {
postService.updateAllSummary(postSummary); postService.updateAllSummary(postSummary);
return true;
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("更新摘要失败:{}", e.getMessage());
return false; e.printStackTrace();
return new JsonResult(ResultCode.FAIL.getCode(), "更新失败!");
} }
return new JsonResult(ResultCode.SUCCESS.getCode(), "所有文章摘要更新成功!");
} }
/** /**
@ -360,13 +365,13 @@ public class PostController extends BaseController {
* *
* *
* @param baiduToken baiduToken * @param baiduToken baiduToken
* @return true or false * @return JsonResult
*/ */
@GetMapping(value = "/pushAllToBaidu") @GetMapping(value = "/pushAllToBaidu")
@ResponseBody @ResponseBody
public boolean pushAllToBaidu(@PathParam("baiduToken") String baiduToken) { public JsonResult pushAllToBaidu(@PathParam("baiduToken") String baiduToken) {
if (StringUtils.isEmpty(baiduToken)) { if (StringUtils.isEmpty(baiduToken)) {
return false; return new JsonResult(ResultCode.FAIL.getCode(), "百度推送Token为空");
} }
String blogUrl = HaloConst.OPTIONS.get(BlogProperties.BLOG_URL.getProp()); String blogUrl = HaloConst.OPTIONS.get(BlogProperties.BLOG_URL.getProp());
List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc()); List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc());
@ -379,8 +384,8 @@ public class PostController extends BaseController {
} }
String result = HaloUtils.baiduPost(blogUrl, baiduToken, urls.toString()); String result = HaloUtils.baiduPost(blogUrl, baiduToken, urls.toString());
if (StringUtils.isEmpty(result)) { if (StringUtils.isEmpty(result)) {
return false; return new JsonResult(ResultCode.FAIL.getCode(), "推送所有文章成功!");
} }
return true; return new JsonResult(ResultCode.SUCCESS.getCode(), "推送成功!");
} }
} }

View File

@ -43,7 +43,7 @@ public class TagController {
try { try {
tagService.saveByTag(tag); tagService.saveByTag(tag);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("新增/修改标签失败:{}", e.getMessage());
} }
return "redirect:/admin/tag"; return "redirect:/admin/tag";
} }
@ -73,7 +73,7 @@ public class TagController {
Tag tag = tagService.removeByTagId(tagId); Tag tag = tagService.removeByTagId(tagId);
log.info("删除的标签:" + tag); log.info("删除的标签:" + tag);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("删除标签失败:{}", e.getMessage());
} }
return "redirect:/admin/tag"; return "redirect:/admin/tag";
} }

View File

@ -119,7 +119,7 @@ public class ThemeController extends BaseController {
return new JsonResult(ResultCode.FAIL.getCode(),"请选择上传的主题!"); return new JsonResult(ResultCode.FAIL.getCode(),"请选择上传的主题!");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("上传主题失败:", e.getMessage()); log.error("上传主题失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"主题上传失败!"); return new JsonResult(ResultCode.FAIL.getCode(),"主题上传失败!");
} }
return new JsonResult(ResultCode.SUCCESS.getCode(),"主题上传成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(),"主题上传成功!");

View File

@ -57,7 +57,7 @@ public class UserController {
return new JsonResult(ResultCode.FAIL.getCode(),"修改失败!"); return new JsonResult(ResultCode.FAIL.getCode(),"修改失败!");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("修改用户资料失败:{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"修改失败!"); return new JsonResult(ResultCode.FAIL.getCode(),"修改失败!");
} }
return new JsonResult(ResultCode.SUCCESS.getCode(),"修改成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(),"修改成功!");
@ -88,7 +88,7 @@ public class UserController {
return new JsonResult(ResultCode.FAIL.getCode(),"原密码错误!"); return new JsonResult(ResultCode.FAIL.getCode(),"原密码错误!");
} }
} catch (Exception e) { } catch (Exception e) {
log.error("修改密码未知错误,{0}", e.getMessage()); log.error("修改密码失败{}", e.getMessage());
return new JsonResult(ResultCode.FAIL.getCode(),"密码修改失败!"); return new JsonResult(ResultCode.FAIL.getCode(),"密码修改失败!");
} }
return new JsonResult(ResultCode.SUCCESS.getCode(),"修改密码成功!"); return new JsonResult(ResultCode.SUCCESS.getCode(),"修改密码成功!");

View File

@ -26,6 +26,7 @@ public abstract class BaseController {
/** /**
* 404 * 404
*
* @return redirect:/404 * @return redirect:/404
*/ */
public String renderNotFound() { public String renderNotFound() {

View File

@ -104,6 +104,12 @@ public class FrontCommentController {
public JsonResult newComment(@ModelAttribute("comment") Comment comment, public JsonResult newComment(@ModelAttribute("comment") Comment comment,
@ModelAttribute("post") Post post, @ModelAttribute("post") Post post,
HttpServletRequest request) { HttpServletRequest request) {
if (StringUtils.equals(StringUtils.trim(comment.getCommentAuthor()), "")) {
return new JsonResult(ResultCode.FAIL.getCode(), "请正确输入昵称!");
}
if (StringUtils.equals(StringUtils.trim(comment.getCommentContent()), "")) {
return new JsonResult(ResultCode.FAIL.getCode(), "请正确输入评论内容!");
}
try{ try{
Comment lastComment = null; Comment lastComment = null;
post = postService.findByPostId(post.getPostId()).get(); post = postService.findByPostId(post.getPostId()).get();
@ -163,7 +169,7 @@ public class FrontCommentController {
map.put("commentContent", comment.getCommentContent()); map.put("commentContent", comment.getCommentContent());
mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail/mail_admin.ftl"); mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail/mail_admin.ftl");
} catch (Exception e) { } catch (Exception e) {
log.error("邮件服务器未配置:", e.getMessage()); log.error("邮件服务器未配置:{}", e.getMessage());
} }
} }
} }

View File

@ -63,16 +63,16 @@
<#switch comment.commentStatus> <#switch comment.commentStatus>
<#case 0> <#case 0>
<button class="btn btn-primary btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')" <#if comment.isAdmin==1>disabled</#if>>回复</button> <button class="btn btn-primary btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')" <#if comment.isAdmin==1>disabled</#if>>回复</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=0','确定移动到回收站?')">丢弃</button> <button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=0&page=${comments.number}','确定移动到回收站?')">丢弃</button>
<#break > <#break >
<#case 1> <#case 1>
<a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=1">通过</a> <a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=1">通过</a>
<button class="btn btn-info btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')">通过并回复</button> <button class="btn btn-info btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')">通过并回复</button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=1','确定移动到回收站?')">丢弃</button> <button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=1&page=${comments.number}','确定移动到回收站?')">丢弃</button>
<#break > <#break >
<#case 2> <#case 2>
<a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=2">还原</a> <a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=2">还原</a>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/remove?commentId=${comment.commentId?c}&status=2','确定要永久删除?')">删除</button> <button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/remove?commentId=${comment.commentId?c}&status=2&page=${comments.number}','确定要永久删除?')">删除</button>
<#break > <#break >
</#switch> </#switch>
</td> </td>

View File

@ -673,7 +673,7 @@
postSummary : $('#postSummary').val() postSummary : $('#postSummary').val()
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==1){
showMsg("所有文章摘要更新成功!","success",1000); showMsg("所有文章摘要更新成功!","success",1000);
}else{ }else{
showMsg("更新失败!","success",2000); showMsg("更新失败!","success",2000);
@ -693,10 +693,22 @@
baiduToken : $('#baiduToken').val() baiduToken : $('#baiduToken').val()
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==1){
showMsg("推送所有文章成功!","success",1000); showMsg("推送所有文章成功!","success",1000);
}else{ }else{
showMsg("推送失败!","success",2000); $.toast({
text: data.msg,
heading: '提示',
icon: icon,
showHideTransition: 'fade',
allowToastClose: true,
hideAfter: hideAfter,
stack: 1,
position: 'top-center',
textAlign: 'left',
loader: true,
loaderBg: '#ffffff'
});
} }
} }
}); });

View File

@ -183,7 +183,7 @@
'postUrl': $('#newPostUrl').val() 'postUrl': $('#newPostUrl').val()
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==0){
showMsg("该路径已经存在!","info",2000); showMsg("该路径已经存在!","info",2000);
return; return;
}else{ }else{

View File

@ -94,7 +94,7 @@
galleryId : ${gallery.galleryId?c} galleryId : ${gallery.galleryId?c}
}, },
success: function (data) { success: function (data) {
if(data==true){ if(data.code==1){
$.toast({ $.toast({
text: "删除成功!", text: "删除成功!",
heading: '提示', heading: '提示',

View File

@ -379,11 +379,15 @@
localStorage.setItem('url', url.val()); localStorage.setItem('url', url.val());
if(data.code==1){ if(data.code==1){
$('.comment-input-content').val(""); $('.comment-input-content').val("");
}
$(".native-message").html("<span>"+data.msg+"</span>"); $(".native-message").html("<span>"+data.msg+"</span>");
}else{
$(".native-message").html("<span style='color:red'>"+data.msg+"</span>");
}
$(".native-message").fadeIn(1000); $(".native-message").fadeIn(1000);
setTimeout(function () { setTimeout(function () {
window.location.reload(); $(".native-message").fadeOut(1000);
$("#btn-push").removeAttr("disabled");
$("#btn-push").html("提交");
},1500); },1500);
} }
}); });