From 28e7e8d97cb4f4417541fa2250cc084940cce4cb Mon Sep 17 00:00:00 2001 From: josxy <112438556@qq.com> Date: Sun, 4 Jul 2021 03:39:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AEEND?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/allms/MxBlogApplication.java | 6 +- .../java/cn/allms/aspect/LogAspectOld.java | 129 +-- src/main/java/cn/allms/config/LogAspect.java | 3 +- src/main/java/cn/allms/config/MyConfig.java | 2 +- .../cn/allms/config/RandomPicturesConfig.java | 1 + .../allms/controller/AboutShowController.java | 2 +- .../allms/controller/CommentController.java | 88 +- .../cn/allms/controller/IndexController.java | 78 +- .../allms/controller/TagShowController.java | 10 +- .../allms/controller/TypeShowController.java | 10 +- .../controller/admin/BlogController.java | 46 +- .../controller/admin/LoginController.java | 13 +- .../allms/controller/admin/TagController.java | 31 +- .../controller/admin/TypeController.java | 34 +- .../java/cn/allms/dao/BlogRepository.java | 4 +- .../java/cn/allms/dao/CommentRepository.java | 2 +- src/main/java/cn/allms/dao/TagRepository.java | 2 +- .../java/cn/allms/dao/TypeRepository.java | 3 +- .../java/cn/allms/dao/UserRepository.java | 3 +- .../cn/allms/exception/NotFoundException.java | 2 +- .../handler/ControllerExceptionHandler.java | 2 + .../allms/interceptor/LoginInterceptor.java | 2 +- .../java/cn/allms/service/BlogService.java | 21 +- .../java/cn/allms/service/CommentService.java | 2 + .../java/cn/allms/service/TagService.java | 7 + .../java/cn/allms/service/TypeService.java | 9 +- .../java/cn/allms/service/Userservice.java | 1 + .../allms/service/impl/BlogServiceImpl.java | 29 +- .../service/impl/CommentServiceImpl.java | 4 +- .../cn/allms/service/impl/TagServiceImpl.java | 10 +- .../allms/service/impl/TypeServiceImpl.java | 4 +- src/main/java/cn/allms/util/CommentUtil.java | 13 +- src/main/java/cn/allms/util/MD5Utils.java | 7 +- .../java/cn/allms/util/MarkdownUtils.java | 2 + src/main/java/cn/allms/util/MyBeanUtils.java | 3 +- src/main/resources/application-dev.yml | 13 +- src/main/resources/application-pro.yml | 3 +- src/main/resources/i18n/message.properties | 4 - .../resources/i18n/message_en_US.properties | 6 - .../resources/i18n/message_zh_CN.properties | 3 - .../{ => logback}/logback-spring.xml | 0 src/main/resources/{ => static}/favicon.ico | Bin src/main/resources/templates/_fragments.html | 77 +- src/main/resources/templates/about.html | 260 +++--- .../resources/templates/admin/_fragments.html | 29 +- .../templates/admin/blogs-input.html | 528 ++++++------ src/main/resources/templates/admin/blogs.html | 420 +++++----- src/main/resources/templates/admin/index.html | 191 ++--- src/main/resources/templates/admin/login.html | 87 +- .../resources/templates/admin/tags-input.html | 285 +++---- src/main/resources/templates/admin/tags.html | 24 +- .../templates/admin/types-input.html | 287 +++---- src/main/resources/templates/admin/types.html | 274 +++--- src/main/resources/templates/archives.html | 190 +++-- src/main/resources/templates/blog.html | 791 ++++++++++-------- src/main/resources/templates/error/404.html | 30 +- src/main/resources/templates/error/500.html | 2 +- src/main/resources/templates/error/error.html | 54 +- src/main/resources/templates/index.html | 499 +++++------ src/main/resources/templates/search.html | 296 +++---- src/main/resources/templates/tags.html | 374 +++++---- src/main/resources/templates/types.html | 549 ++++++------ 62 files changed, 3040 insertions(+), 2821 deletions(-) rename src/main/resources/{ => logback}/logback-spring.xml (100%) rename src/main/resources/{ => static}/favicon.ico (100%) diff --git a/src/main/java/cn/allms/MxBlogApplication.java b/src/main/java/cn/allms/MxBlogApplication.java index c489038..71e0719 100644 --- a/src/main/java/cn/allms/MxBlogApplication.java +++ b/src/main/java/cn/allms/MxBlogApplication.java @@ -9,7 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MxBlogApplication { - public static void main(String[] args) { - SpringApplication.run(MxBlogApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(MxBlogApplication.class, args); + } } diff --git a/src/main/java/cn/allms/aspect/LogAspectOld.java b/src/main/java/cn/allms/aspect/LogAspectOld.java index c0eef8b..5bdba6c 100644 --- a/src/main/java/cn/allms/aspect/LogAspectOld.java +++ b/src/main/java/cn/allms/aspect/LogAspectOld.java @@ -17,81 +17,82 @@ import java.util.Arrays; @Component public class LogAspectOld { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); - /** - * 切点:cn.allms.controller - */ - //@Pointcut("execution(* cn.allms.controller.*.*(..))") - public void log(){} + /** + * 切点:cn.allms.controller + */ + //@Pointcut("execution(* cn.allms.controller.*.*(..))") + public void log() { + } // @Before("log()") - public void doBefore(JoinPoint joinPoint){ - // 获取request对象 - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - assert attributes != null; - HttpServletRequest request = attributes.getRequest(); - // URL - String url = request.getRequestURL().toString(); - // IP - String ip = request.getRemoteAddr(); - // 方法全名 = 类名.方法名 - String classMethod = joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName(); - // 请求对象 - Object[] args = joinPoint.getArgs(); - RequestLog requestLog = new RequestLog(url,ip,classMethod,args); + public void doBefore(JoinPoint joinPoint) { + // 获取request对象 + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + assert attributes != null; + HttpServletRequest request = attributes.getRequest(); + // URL + String url = request.getRequestURL().toString(); + // IP + String ip = request.getRemoteAddr(); + // 方法全名 = 类名.方法名 + String classMethod = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName(); + // 请求对象 + Object[] args = joinPoint.getArgs(); + RequestLog requestLog = new RequestLog(url, ip, classMethod, args); - logger.info("Request : {}",requestLog); - } + logger.info("Request : {}", requestLog); + } - //@After("log()") - public void doAfter(){ + //@After("log()") + public void doAfter() { // logger.info("-------doafter-----------"); - } + } - public void doAfterReturn(Object result){ - logger.info("控制器方法名称Result : {}",result); - } + public void doAfterReturn(Object result) { + logger.info("控制器方法名称Result : {}", result); + } - /** - * 内部类:用于存放请求信息,用日志的方式将其记录下来 - */ - private class RequestLog{ - /** - * 请求地址 - */ - private String url; - /** - * 请求ip - */ - private String ip; - /** - * 请求方法 - */ - private String classMethod; - /** - * 请求参数集合 - */ - private Object[] args; + /** + * 内部类:用于存放请求信息,用日志的方式将其记录下来 + */ + private class RequestLog { + /** + * 请求地址 + */ + private String url; + /** + * 请求ip + */ + private String ip; + /** + * 请求方法 + */ + private String classMethod; + /** + * 请求参数集合 + */ + private Object[] args; - public RequestLog(String url, String ip, String classMethod, Object[] args) { - this.url = url; - this.ip = ip; - this.classMethod = classMethod; - this.args = args; - } + public RequestLog(String url, String ip, String classMethod, Object[] args) { + this.url = url; + this.ip = ip; + this.classMethod = classMethod; + this.args = args; + } - @Override - public String toString() { - return "RequestLog{" + - "url='" + url + '\'' + - ", ip='" + ip + '\'' + - ", classMethod='" + classMethod + '\'' + - ", args=" + Arrays.toString(args) + - '}'; - } - } + @Override + public String toString() { + return "RequestLog{" + + "url='" + url + '\'' + + ", ip='" + ip + '\'' + + ", classMethod='" + classMethod + '\'' + + ", args=" + Arrays.toString(args) + + '}'; + } + } } diff --git a/src/main/java/cn/allms/config/LogAspect.java b/src/main/java/cn/allms/config/LogAspect.java index ce45766..9525258 100644 --- a/src/main/java/cn/allms/config/LogAspect.java +++ b/src/main/java/cn/allms/config/LogAspect.java @@ -25,7 +25,8 @@ import javax.servlet.http.HttpServletRequest; @Aspect public class LogAspect { @Pointcut("execution(* cn.allms.controller.*.*(..))") - public void webLog(){} + public void webLog() { + } @Before("webLog()") public void doBefore(JoinPoint joinPoint) { diff --git a/src/main/java/cn/allms/config/MyConfig.java b/src/main/java/cn/allms/config/MyConfig.java index 582b173..8496dd8 100644 --- a/src/main/java/cn/allms/config/MyConfig.java +++ b/src/main/java/cn/allms/config/MyConfig.java @@ -9,7 +9,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter * 配置类 */ @Configuration -public class MyConfig extends WebMvcConfigurerAdapter{ +public class MyConfig extends WebMvcConfigurerAdapter { //重写拦截器 @Override diff --git a/src/main/java/cn/allms/config/RandomPicturesConfig.java b/src/main/java/cn/allms/config/RandomPicturesConfig.java index bc86e64..9dc1c6a 100644 --- a/src/main/java/cn/allms/config/RandomPicturesConfig.java +++ b/src/main/java/cn/allms/config/RandomPicturesConfig.java @@ -19,6 +19,7 @@ public class RandomPicturesConfig { /** * TODO * 随机获取一种图片 + * * @return */ public String getRandomPicAddr() { diff --git a/src/main/java/cn/allms/controller/AboutShowController.java b/src/main/java/cn/allms/controller/AboutShowController.java index baa9d00..ffbdafe 100644 --- a/src/main/java/cn/allms/controller/AboutShowController.java +++ b/src/main/java/cn/allms/controller/AboutShowController.java @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.GetMapping; @Controller public class AboutShowController { @GetMapping("/about") - public String about(){ + public String about() { return "about"; } } diff --git a/src/main/java/cn/allms/controller/CommentController.java b/src/main/java/cn/allms/controller/CommentController.java index c7fcb40..974276c 100644 --- a/src/main/java/cn/allms/controller/CommentController.java +++ b/src/main/java/cn/allms/controller/CommentController.java @@ -21,54 +21,56 @@ import javax.servlet.http.HttpSession; @Controller public class CommentController { - @Autowired - private CommentService commentServiceImpl; + @Autowired + private CommentService commentServiceImpl; - @Autowired - private BlogService blogServiceImpl; + @Autowired + private BlogService blogServiceImpl; - @Value("${comment.avatar}") - private String avatar; + @Value("${comment.avatar}") + private String avatar; - @Value("${comment.v2exUrl}") - private String v2exUrl; + @Value("${comment.v2exUrl}") + private String v2exUrl; - /** - * 显示评论列表 - * @param blogId - * @param model - * @return - */ - @GetMapping("/comments/{blogId}") - public String comments(@PathVariable Long blogId, Model model){ - model.addAttribute("comments",commentServiceImpl.listCommentByBlogId(blogId)); - return "blog :: commentList"; - } + /** + * 显示评论列表 + * + * @param blogId + * @param model + * @return + */ + @GetMapping("/comments/{blogId}") + public String comments(@PathVariable Long blogId, Model model) { + model.addAttribute("comments", commentServiceImpl.listCommentByBlogId(blogId)); + return "blog :: commentList"; + } - /** - * 提交评论 - * @param comment - * @return - */ - @PostMapping("/comments") - public String post(Comment comment, HttpSession session){ - Long blogId = comment.getBlog().getId(); - //处理评论和博客之间的关系 - comment.setBlog(blogServiceImpl.getBlog(blogId)); - User user = (User) session.getAttribute("user"); - //管理员发 - if(user != null){ - comment.setAvatar(user.getAvatar()); - comment.setAdminComment(true); - comment.setNickname(user.getNickname()); - comment.setEmail(user.getEmail()); - //普通用户 - } else { - comment.setAvatar(v2exUrl + MD5Utils.code(comment.getEmail())); - } - commentServiceImpl.saveComment(comment); - return "redirect:/comments/" +blogId; - } + /** + * 提交评论 + * + * @param comment + * @return + */ + @PostMapping("/comments") + public String post(Comment comment, HttpSession session) { + Long blogId = comment.getBlog().getId(); + //处理评论和博客之间的关系 + comment.setBlog(blogServiceImpl.getBlog(blogId)); + User user = (User) session.getAttribute("user"); + //管理员发 + if (user != null) { + comment.setAvatar(user.getAvatar()); + comment.setAdminComment(true); + comment.setNickname(user.getNickname()); + comment.setEmail(user.getEmail()); + //普通用户 + } else { + comment.setAvatar(v2exUrl + MD5Utils.code(comment.getEmail())); + } + commentServiceImpl.saveComment(comment); + return "redirect:/comments/" + blogId; + } } diff --git a/src/main/java/cn/allms/controller/IndexController.java b/src/main/java/cn/allms/controller/IndexController.java index e679bfb..93b8e3b 100644 --- a/src/main/java/cn/allms/controller/IndexController.java +++ b/src/main/java/cn/allms/controller/IndexController.java @@ -20,59 +20,61 @@ import org.springframework.web.bind.annotation.RequestParam; @Controller public class IndexController { - @Autowired - private BlogService blogServiceImpl; + @Autowired + private BlogService blogServiceImpl; - @Autowired - private TypeService typeServiceImpl; + @Autowired + private TypeService typeServiceImpl; - @Autowired - private TagService tagServiceImpl; + @Autowired + private TagService tagServiceImpl; - /** - * 首页面显示 - * @param model - * @param pageable - * @return - */ - @GetMapping("/") - public String index(Model model, @PageableDefault(size = 8, sort = {"updateTime"}, direction = Sort.Direction.DESC) - Pageable pageable){ - //1. 获取分页的博客列表 - model.addAttribute("page",blogServiceImpl.ListBlog(pageable)); - //2. 获取分类的内容(显示6条) - model.addAttribute("types",typeServiceImpl.listTypeTop(6)); - //3. 获取标签的内容 - model.addAttribute("tags",tagServiceImpl.ListTagTop(10)); - //4. 显示推荐博客列表 - model.addAttribute("recommendBlogs",blogServiceImpl.listRecommendBlogTop(8)); - return "index"; - } + /** + * 首页面显示 + * + * @param model + * @param pageable + * @return + */ + @GetMapping("/") + public String index(Model model, @PageableDefault(size = 8, sort = {"updateTime"}, direction = Sort.Direction.DESC) + Pageable pageable) { + //1. 获取分页的博客列表 + model.addAttribute("page", blogServiceImpl.ListBlog(pageable)); + //2. 获取分类的内容(显示6条) + model.addAttribute("types", typeServiceImpl.listTypeTop(6)); + //3. 获取标签的内容 + model.addAttribute("tags", tagServiceImpl.ListTagTop(10)); + //4. 显示推荐博客列表 + model.addAttribute("recommendBlogs", blogServiceImpl.listRecommendBlogTop(8)); + return "index"; + } - /** - * 导航栏中的搜索功能实现 - * @param pageable - * @return - * @param model - */ + /** + * 导航栏中的搜索功能实现 + * + * @param pageable + * @param model + * @return + */ @PostMapping("/search") public String search(@PageableDefault(size = 8, sort = {"updateTime"}, direction = Sort.Direction.DESC) Pageable pageable, @RequestParam String query, Model model) { - model.addAttribute("page", blogServiceImpl.ListBlog(pageable, "%"+query+"%")); + model.addAttribute("page", blogServiceImpl.ListBlog(pageable, "%" + query + "%")); model.addAttribute("query", query); return "search"; } @GetMapping("/blog/{id}") - public String blog(@PathVariable("id") Long id,Model model){ - model.addAttribute("blog",blogServiceImpl.getAadConvertBlog(id)); + public String blog(@PathVariable("id") Long id, Model model) { + model.addAttribute("blog", blogServiceImpl.getAadConvertBlog(id)); return "blog"; } @GetMapping("/footer/newblog") - public String newblos(Model model){ - model.addAttribute("newblogs",blogServiceImpl.listRecommendBlogTop(3)); - return "_fragments :: newblogList"; - } + public String newblos(Model model) { + model.addAttribute("newblogs", blogServiceImpl.listRecommendBlogTop(3)); + return "_fragments :: newblogList"; + } } diff --git a/src/main/java/cn/allms/controller/TagShowController.java b/src/main/java/cn/allms/controller/TagShowController.java index aca4d79..8ded412 100644 --- a/src/main/java/cn/allms/controller/TagShowController.java +++ b/src/main/java/cn/allms/controller/TagShowController.java @@ -1,8 +1,6 @@ package cn.allms.controller; - - import cn.allms.po.Tag; import cn.allms.service.TagService; import cn.allms.vo.BlogQuery; @@ -36,16 +34,16 @@ public class TagShowController { @GetMapping("/tags/{id}") public String tags(Model model, @PageableDefault(size = 8, sort = {"updateTime"}, direction = Sort.Direction.DESC) - @PathVariable Long id, Pageable pageable) { + @PathVariable Long id, Pageable pageable) { List tags = tagServiceImpl.ListTagTop(10000); if (id == -1 && tags.size() > 0) { id = tags.get(0).getId(); } BlogQuery blogQuery = new BlogQuery(); - model.addAttribute("tags",tags); - model.addAttribute("page",blogServiceImpl.ListBlog(id,pageable)); - model.addAttribute("avtiveTagId",id); + model.addAttribute("tags", tags); + model.addAttribute("page", blogServiceImpl.ListBlog(id, pageable)); + model.addAttribute("avtiveTagId", id); return "tags"; } diff --git a/src/main/java/cn/allms/controller/TypeShowController.java b/src/main/java/cn/allms/controller/TypeShowController.java index 6d57133..8ad4fcb 100644 --- a/src/main/java/cn/allms/controller/TypeShowController.java +++ b/src/main/java/cn/allms/controller/TypeShowController.java @@ -33,17 +33,17 @@ public class TypeShowController { @GetMapping("/types/{id}") public String types(Model model, @PageableDefault(size = 8, sort = {"updateTime"}, direction = Sort.Direction.DESC) - @PathVariable Long id, Pageable pageable) { + @PathVariable Long id, Pageable pageable) { List types = typeServiceImpl.listTypeTop(10000); - if (id == -1 && types.size() > 0){ + if (id == -1 && types.size() > 0) { id = types.get(0).getId(); } BlogQuery blogQuery = new BlogQuery(); blogQuery.setTypeId(id); - model.addAttribute("types",types); - model.addAttribute("page",blogServiceImpl.ListBlog(pageable,blogQuery)); - model.addAttribute("avtiveTypeId",id); + model.addAttribute("types", types); + model.addAttribute("page", blogServiceImpl.ListBlog(pageable, blogQuery)); + model.addAttribute("avtiveTypeId", id); return "types"; } diff --git a/src/main/java/cn/allms/controller/admin/BlogController.java b/src/main/java/cn/allms/controller/admin/BlogController.java index 3631367..362e345 100644 --- a/src/main/java/cn/allms/controller/admin/BlogController.java +++ b/src/main/java/cn/allms/controller/admin/BlogController.java @@ -36,19 +36,19 @@ public class BlogController { /** * 博客发布页面url */ - private static final String INPUT="admin/blogs-input"; - private static final String HEAD_URL="https://api.rainss.cn/random.php?t="; - private static final String HEAD_URL_1="https://api.rainss.cn/acgimgurl/acgurl.php?t="; + private static final String INPUT = "admin/blogs-input"; + private static final String HEAD_URL = "https://api.rainss.cn/random.php?t="; + private static final String HEAD_URL_1 = "https://api.rainss.cn/acgimgurl/acgurl.php?t="; /** * 显示分页查询到的博客列表页面url */ - private static final String LIST="admin/blogs"; + private static final String LIST = "admin/blogs"; /** * 局部刷新表格查询到的数据url */ - private static final String REDIRECT_LIST="redirect:/admin/blogs"; + private static final String REDIRECT_LIST = "redirect:/admin/blogs"; @Autowired private BlogService blogServiceImpl; @@ -61,6 +61,7 @@ public class BlogController { /** * 分页显示博客列表 + * * @param model * @param pageable * @param blog @@ -75,6 +76,7 @@ public class BlogController { /** * 联合查询博客列表 + * * @param model * @param pageable * @param blog @@ -89,12 +91,13 @@ public class BlogController { /** * 新增博客页面 + * * @param model * @return */ @GetMapping("/blogs/input") - public String inputBlog(Model model){ - model.addAttribute("firstPicture",HEAD_URL_1 + System.currentTimeMillis()); + public String inputBlog(Model model) { + model.addAttribute("firstPicture", HEAD_URL_1 + System.currentTimeMillis()); setTypeAadTag(model); return INPUT; } @@ -102,68 +105,71 @@ public class BlogController { /** * 提交博客 + * * @param blog * @param attributes * @param session * @return */ @PostMapping("/blogs") - public String post(Blog blog, RedirectAttributes attributes , HttpSession session){ + public String post(Blog blog, RedirectAttributes attributes, HttpSession session) { blog.setUser((User) session.getAttribute("user")); blog.setType(typeServiceImpl.getType(blog.getType().getId())); blog.setTags(tagServiceImpl.ListTag(blog.getTagIds())); Blog b; Date date = new Date(); //新增博客 - if(blog.getId() == null){ + if (blog.getId() == null) { blog.setUpdateTime(date); blog.setCreateTime(date); blog.setViews(0); b = blogServiceImpl.saveBlog(blog); } else {//更新博客 - b = blogServiceImpl.updateBlog(blog.getId(),blog); + b = blogServiceImpl.updateBlog(blog.getId(), blog); } - if (b==null){ - attributes.addFlashAttribute("message","操作失败"); - }else { - attributes.addFlashAttribute("message","操作成功"); + if (b == null) { + attributes.addFlashAttribute("message", "操作失败"); + } else { + attributes.addFlashAttribute("message", "操作成功"); } return REDIRECT_LIST; } /** * 删除博客 + * * @param id * @return */ @GetMapping("/blogs/{id}/delete") - public String deleteBlog(@PathVariable("id") Long id){ + public String deleteBlog(@PathVariable("id") Long id) { blogServiceImpl.deleteBlog(id); return REDIRECT_LIST; } /** * 修改博客页面 + * * @param model * @return */ @GetMapping("/blogs/{id}/input") - public String editBlog(@PathVariable("id") Long id,Model model){ + public String editBlog(@PathVariable("id") Long id, Model model) { setTypeAadTag(model); Blog blog = blogServiceImpl.getBlog(id); //处理tagIds blog.init(); - model.addAttribute("firstPicture",HEAD_URL_1 + System.currentTimeMillis()); - model.addAttribute("blog",blog); + model.addAttribute("firstPicture", HEAD_URL_1 + System.currentTimeMillis()); + model.addAttribute("blog", blog); return INPUT; } - private void setTypeAadTag(Model model){ + private void setTypeAadTag(Model model) { /*博客查询,为后面的编辑博客做准备*/ model.addAttribute("blog", new Blog()); /*分类查询*/ model.addAttribute("types", typeServiceImpl.listType()); /*标签查询*/ - model.addAttribute("tags",tagServiceImpl.ListTag()); + model.addAttribute("tags", tagServiceImpl.ListTag()); } } diff --git a/src/main/java/cn/allms/controller/admin/LoginController.java b/src/main/java/cn/allms/controller/admin/LoginController.java index f295500..ae3e74a 100644 --- a/src/main/java/cn/allms/controller/admin/LoginController.java +++ b/src/main/java/cn/allms/controller/admin/LoginController.java @@ -27,15 +27,17 @@ public class LoginController { /** * 显示用户登录页面 + * * @return */ @GetMapping - public String loginPage(){ + public String loginPage() { return "admin/login"; } /** * 用户登录 + * * @param username * @param password * @param session @@ -47,10 +49,10 @@ public class LoginController { @RequestParam String password, HttpSession session, RedirectAttributes attributes) { - User user = userservice.checkUser(username,password); - if (user != null ){ + User user = userservice.checkUser(username, password); + if (user != null) { user.setPassword(null); - session.setAttribute("user",user); + session.setAttribute("user", user); return "admin/index"; } else { attributes.addFlashAttribute("message", "用户名和密码错误"); @@ -60,11 +62,12 @@ public class LoginController { /** * 用户注销 + * * @param session * @return */ @GetMapping("/logout") - public String logout(HttpSession session){ + public String logout(HttpSession session) { session.removeAttribute("user"); return "redirect:/admin"; } diff --git a/src/main/java/cn/allms/controller/admin/TagController.java b/src/main/java/cn/allms/controller/admin/TagController.java index 996629a..8b382a9 100644 --- a/src/main/java/cn/allms/controller/admin/TagController.java +++ b/src/main/java/cn/allms/controller/admin/TagController.java @@ -26,32 +26,35 @@ import javax.validation.Valid; public class TagController { @Autowired - private TagService tagServiceImpl; + private TagService tagServiceImpl; /** * 分页查询标签列表 + * * @return */ @GetMapping("/tags") - public String types(@PageableDefault(size = 8,sort = {"id"},direction = Sort.Direction.DESC) + public String types(@PageableDefault(size = 8, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, Model model) { - model.addAttribute("page",tagServiceImpl.ListTag(pageable)); + model.addAttribute("page", tagServiceImpl.ListTag(pageable)); return "admin/tags"; } /** * 显示添加标签页面 + * * @param model * @return */ @GetMapping("/tags/input") - public String showInput(Model model){ - model.addAttribute("tag",new Tag()); + public String showInput(Model model) { + model.addAttribute("tag", new Tag()); return "admin/tags-input"; } /** * 新增标签 + * * @param tag * @param result * @param attributes @@ -75,19 +78,22 @@ public class TagController { return "redirect:/admin/tags"; } + /** * 显示添加标签页面 + * * @param model * @return */ @GetMapping("/tags/{id}/input") - public String editInput(@PathVariable("id") Long id, Model model){ - model.addAttribute("tag",tagServiceImpl.getTag(id)); + public String editInput(@PathVariable("id") Long id, Model model) { + model.addAttribute("tag", tagServiceImpl.getTag(id)); return "admin/tags-input"; } /** * 修改标签名 + * * @param tag * @param result * @param id @@ -95,16 +101,16 @@ public class TagController { * @return */ @PostMapping("/tags/{id}") - public String editPost(@Valid Tag tag,BindingResult result,@PathVariable("id")Long id,RedirectAttributes attributes){ + public String editPost(@Valid Tag tag, BindingResult result, @PathVariable("id") Long id, RedirectAttributes attributes) { Tag tag1 = tagServiceImpl.getTagByName(tag.getName()); if (tag1 != null) { - result.rejectValue("name","nameError","不能添加重复的分类"); + result.rejectValue("name", "nameError", "不能添加重复的分类"); } if (result.hasErrors()) { return "admin/tags-input"; } Tag t = tagServiceImpl.updateTag(id, tag); - if (t == null ) { + if (t == null) { attributes.addFlashAttribute("message", "更新失败"); } else { attributes.addFlashAttribute("message", "更新成功"); @@ -114,14 +120,15 @@ public class TagController { /** * 删除功能 + * * @param id * @param attributes * @return */ @GetMapping("/tags/{id}/delete") - public String deleteById(@PathVariable("id") Long id,RedirectAttributes attributes){ + public String deleteById(@PathVariable("id") Long id, RedirectAttributes attributes) { tagServiceImpl.deleteTag(id); - attributes.addFlashAttribute("message","删除成功"); + attributes.addFlashAttribute("message", "删除成功"); return "redirect:/admin/tags"; } } diff --git a/src/main/java/cn/allms/controller/admin/TypeController.java b/src/main/java/cn/allms/controller/admin/TypeController.java index 0b052c7..cbd93ae 100644 --- a/src/main/java/cn/allms/controller/admin/TypeController.java +++ b/src/main/java/cn/allms/controller/admin/TypeController.java @@ -32,12 +32,13 @@ public class TypeController { /** * 分页查询分类列表 + * * @return */ @GetMapping("/types") - public String types(@PageableDefault(size = 8,sort = {"id"},direction = Sort.Direction.DESC) + public String types(@PageableDefault(size = 8, sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable, Model model) { - model.addAttribute("page",typeServiceImpl.ListType(pageable)); + model.addAttribute("page", typeServiceImpl.ListType(pageable)); return "admin/types"; } @@ -47,29 +48,30 @@ public class TypeController { * @return */ @GetMapping("/types/input") - public String showInput(Model model){ - model.addAttribute("type",new Type()); + public String showInput(Model model) { + model.addAttribute("type", new Type()); return "admin/types-input"; } /** * 新增分类 + * * @return */ @PostMapping("/types") - public String post(@Valid Type type,BindingResult result, RedirectAttributes attributes) { + public String post(@Valid Type type, BindingResult result, RedirectAttributes attributes) { //1.判断用户名是有重复 Type type1 = typeServiceImpl.getTypeByName(type.getName()); if (type1 != null) { - result.rejectValue("name","nameError","不能添加重复的分类"); + result.rejectValue("name", "nameError", "不能添加重复的分类"); } //2. 后端校验用户名是否为空 if (result.hasErrors()) { return "admin/types-input"; } Type t = typeServiceImpl.saveType(type); - if (t == null ) { + if (t == null) { attributes.addFlashAttribute("message", "新增失败"); } else { attributes.addFlashAttribute("message", "新增成功"); @@ -79,34 +81,36 @@ public class TypeController { /** * 跳转到修改分类页面 + * * @param id * @param model * @return */ @GetMapping("/types/{id}/input") - public String editInput(@PathVariable("id") Long id, Model model){ - model.addAttribute("type",typeServiceImpl.getType(id)); + public String editInput(@PathVariable("id") Long id, Model model) { + model.addAttribute("type", typeServiceImpl.getType(id)); return "admin/types-input"; } /** * 修改分类 + * * @return */ @PostMapping("/types/{id}") - public String editPost(@Valid Type type, BindingResult result,@PathVariable Long id, RedirectAttributes attributes) { + public String editPost(@Valid Type type, BindingResult result, @PathVariable Long id, RedirectAttributes attributes) { Type type1 = typeServiceImpl.getTypeByName(type.getName()); if (type1 != null) { - result.rejectValue("name","nameError","不能添加重复的分类"); + result.rejectValue("name", "nameError", "不能添加重复的分类"); } if (result.hasErrors()) { return "admin/types-input"; } - Type t = typeServiceImpl.updateType(id,type); - if (t == null ) { + Type t = typeServiceImpl.updateType(id, type); + if (t == null) { attributes.addFlashAttribute("message", "更新失败"); } else { attributes.addFlashAttribute("message", "更新成功"); @@ -115,9 +119,9 @@ public class TypeController { } @GetMapping("/types/{id}/delete") - public String deleteTypeById(@PathVariable("id") Long id,RedirectAttributes attributes){ + public String deleteTypeById(@PathVariable("id") Long id, RedirectAttributes attributes) { typeServiceImpl.deleteType(id); - attributes.addFlashAttribute("message","删除成功"); + attributes.addFlashAttribute("message", "删除成功"); return "redirect:/admin/types"; } } diff --git a/src/main/java/cn/allms/dao/BlogRepository.java b/src/main/java/cn/allms/dao/BlogRepository.java index 2969da7..eed23f7 100644 --- a/src/main/java/cn/allms/dao/BlogRepository.java +++ b/src/main/java/cn/allms/dao/BlogRepository.java @@ -18,13 +18,13 @@ import java.util.List; * @version: 1.0 */ -public interface BlogRepository extends JpaRepository,JpaSpecificationExecutor{ +public interface BlogRepository extends JpaRepository, JpaSpecificationExecutor { @Query("select b from Blog b where b.recommend = true") List findTop(Pageable pageable); @Query("select b from Blog b where b.title like ?1 or b.content like ?1") - Page findByQuery(String query,Pageable pageable); + Page findByQuery(String query, Pageable pageable); @Transactional @Modifying diff --git a/src/main/java/cn/allms/dao/CommentRepository.java b/src/main/java/cn/allms/dao/CommentRepository.java index 790abb8..003b0fe 100644 --- a/src/main/java/cn/allms/dao/CommentRepository.java +++ b/src/main/java/cn/allms/dao/CommentRepository.java @@ -13,7 +13,7 @@ import java.util.List; * @Description: com.yrp.dao * @version: 1.0 */ -public interface CommentRepository extends JpaRepository { +public interface CommentRepository extends JpaRepository { List findByBlogIdAndParentCommentNull(Long blogId, Sort sort); diff --git a/src/main/java/cn/allms/dao/TagRepository.java b/src/main/java/cn/allms/dao/TagRepository.java index be507d3..4104f3d 100644 --- a/src/main/java/cn/allms/dao/TagRepository.java +++ b/src/main/java/cn/allms/dao/TagRepository.java @@ -10,7 +10,7 @@ import java.util.List; /** * 标签 */ -public interface TagRepository extends JpaRepository{ +public interface TagRepository extends JpaRepository { Tag findByName(String name); diff --git a/src/main/java/cn/allms/dao/TypeRepository.java b/src/main/java/cn/allms/dao/TypeRepository.java index 5fa0ebe..fbf425c 100644 --- a/src/main/java/cn/allms/dao/TypeRepository.java +++ b/src/main/java/cn/allms/dao/TypeRepository.java @@ -13,13 +13,14 @@ import java.util.List; * @Description: com.yrp.dao * @version: 1.0 */ -public interface TypeRepository extends JpaRepository{ +public interface TypeRepository extends JpaRepository { Type findByName(String name); /** * 查询type按照分页的方式 + * * @param pageable * @return */ diff --git a/src/main/java/cn/allms/dao/UserRepository.java b/src/main/java/cn/allms/dao/UserRepository.java index 0ab5b2a..24c0897 100644 --- a/src/main/java/cn/allms/dao/UserRepository.java +++ b/src/main/java/cn/allms/dao/UserRepository.java @@ -9,9 +9,10 @@ import org.springframework.data.jpa.repository.JpaRepository; * @Description: com.yrp.dao * @version: 1.0 */ -public interface UserRepository extends JpaRepository { +public interface UserRepository extends JpaRepository { /** * 通过用户名和密码查询用户 + * * @param username * @param password * @return diff --git a/src/main/java/cn/allms/exception/NotFoundException.java b/src/main/java/cn/allms/exception/NotFoundException.java index f81cd2b..8ff20ec 100644 --- a/src/main/java/cn/allms/exception/NotFoundException.java +++ b/src/main/java/cn/allms/exception/NotFoundException.java @@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; * 博客为空的异常 */ @ResponseStatus(HttpStatus.NOT_FOUND) -public class NotFoundException extends RuntimeException{ +public class NotFoundException extends RuntimeException { public NotFoundException() { super(); } diff --git a/src/main/java/cn/allms/handler/ControllerExceptionHandler.java b/src/main/java/cn/allms/handler/ControllerExceptionHandler.java index 54365fb..0acba32 100644 --- a/src/main/java/cn/allms/handler/ControllerExceptionHandler.java +++ b/src/main/java/cn/allms/handler/ControllerExceptionHandler.java @@ -14,8 +14,10 @@ import javax.servlet.http.HttpServletRequest; public class ControllerExceptionHandler { private final Logger logger = LoggerFactory.getLogger(ControllerExceptionHandler.class); + /** * 异常处理 + * * @param request * @param e * @return diff --git a/src/main/java/cn/allms/interceptor/LoginInterceptor.java b/src/main/java/cn/allms/interceptor/LoginInterceptor.java index 596741a..9e69aad 100644 --- a/src/main/java/cn/allms/interceptor/LoginInterceptor.java +++ b/src/main/java/cn/allms/interceptor/LoginInterceptor.java @@ -14,7 +14,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter { HttpServletResponse response, Object handler) throws Exception { //1. 用户未登录 - if(request.getSession().getAttribute("user") == null){ + if (request.getSession().getAttribute("user") == null) { response.sendRedirect("/admin"); return false; } diff --git a/src/main/java/cn/allms/service/BlogService.java b/src/main/java/cn/allms/service/BlogService.java index bc24cfd..2c3da86 100644 --- a/src/main/java/cn/allms/service/BlogService.java +++ b/src/main/java/cn/allms/service/BlogService.java @@ -17,6 +17,7 @@ import java.util.Map; public interface BlogService { /** * 通过id查询单条博客 + * * @param id * @return */ @@ -24,6 +25,7 @@ public interface BlogService { /** * 通过id查询单条博客(前端使用) + * * @param id * @return */ @@ -32,6 +34,7 @@ public interface BlogService { /** * 分页查询博客 + * * @param pageable * @param blog * @return @@ -40,38 +43,44 @@ public interface BlogService { /** * 分页查询显示博客列表 + * * @param pageable * @return */ Page ListBlog(Pageable pageable); - Page ListBlog(Long tagId,Pageable pageable); + Page ListBlog(Long tagId, Pageable pageable); /** * 模糊查询分页显示博客列表 + * * @param pageable * @param query * @return */ - Page ListBlog(Pageable pageable,String query); + Page ListBlog(Pageable pageable, String query); /** * 显示推荐的博客列表 + * * @return */ List listRecommendBlogTop(Integer size); /** * 显示归档信息 + * * @return */ - Map> archiveBlog(); + Map> archiveBlog(); Long countBlog(); + /** * 修改 + * * @param blog * @return */ @@ -79,19 +88,19 @@ public interface BlogService { /** * 修改 + * * @param id * @param blog * @return */ - Blog updateBlog(Long id,Blog blog); + Blog updateBlog(Long id, Blog blog); /** * 删除 + * * @param id */ void deleteBlog(Long id); - - } diff --git a/src/main/java/cn/allms/service/CommentService.java b/src/main/java/cn/allms/service/CommentService.java index f2fb15e..4683756 100644 --- a/src/main/java/cn/allms/service/CommentService.java +++ b/src/main/java/cn/allms/service/CommentService.java @@ -12,6 +12,7 @@ public interface CommentService { /** * 通过id查询评论列表 + * * @param blogId * @return */ @@ -19,6 +20,7 @@ public interface CommentService { /** * 保存评论信息 + * * @param comment * @return */ diff --git a/src/main/java/cn/allms/service/TagService.java b/src/main/java/cn/allms/service/TagService.java index bdad0dd..25a571a 100644 --- a/src/main/java/cn/allms/service/TagService.java +++ b/src/main/java/cn/allms/service/TagService.java @@ -13,6 +13,7 @@ public interface TagService { /** * 新增 + * * @return */ Tag saveTag(Tag tag); @@ -20,6 +21,7 @@ public interface TagService { /** * 单个查询 + * * @param id * @return */ @@ -27,6 +29,7 @@ public interface TagService { /** * 分页查询 + * * @param pageable * @return */ @@ -37,6 +40,7 @@ public interface TagService { /** * 查询所有标签 + * * @return */ List ListTag(); @@ -45,6 +49,7 @@ public interface TagService { /** * 修改 + * * @param id * @param tag * @return @@ -53,12 +58,14 @@ public interface TagService { /** * 删除 + * * @param id */ void deleteTag(Long id); /** * 通过分类名称 + * * @return */ Tag getTagByName(String name); diff --git a/src/main/java/cn/allms/service/TypeService.java b/src/main/java/cn/allms/service/TypeService.java index f68b27c..44b9026 100644 --- a/src/main/java/cn/allms/service/TypeService.java +++ b/src/main/java/cn/allms/service/TypeService.java @@ -13,6 +13,7 @@ public interface TypeService { /** * 新增 + * * @return */ Type saveType(Type type); @@ -20,6 +21,7 @@ public interface TypeService { /** * 单个查询 + * * @param id * @return */ @@ -27,6 +29,7 @@ public interface TypeService { /** * 分页查询 + * * @param pageable * @return */ @@ -34,6 +37,7 @@ public interface TypeService { /** * 查询所有分类 + * * @return */ List listType(); @@ -43,20 +47,23 @@ public interface TypeService { /** * 修改 + * * @param id * @param type * @return */ - Type updateType(Long id,Type type); + Type updateType(Long id, Type type); /** * 删除 + * * @param id */ void deleteType(Long id); /** * 通过分类名称查询分类 + * * @return */ Type getTypeByName(String name); diff --git a/src/main/java/cn/allms/service/Userservice.java b/src/main/java/cn/allms/service/Userservice.java index e827a22..5afbf53 100644 --- a/src/main/java/cn/allms/service/Userservice.java +++ b/src/main/java/cn/allms/service/Userservice.java @@ -12,6 +12,7 @@ public interface Userservice { /** * 用户登录检测 + * * @param * @return */ diff --git a/src/main/java/cn/allms/service/impl/BlogServiceImpl.java b/src/main/java/cn/allms/service/impl/BlogServiceImpl.java index f7c53b8..6394b0c 100644 --- a/src/main/java/cn/allms/service/impl/BlogServiceImpl.java +++ b/src/main/java/cn/allms/service/impl/BlogServiceImpl.java @@ -28,8 +28,7 @@ import java.util.*; * @version: 1.0 */ @Service -public class BlogServiceImpl implements BlogService -{ +public class BlogServiceImpl implements BlogService { @Autowired private BlogRepository blogRepository; @@ -43,11 +42,11 @@ public class BlogServiceImpl implements BlogService @Override public Blog getAadConvertBlog(Long id) { Blog blog = blogRepository.findById(id).orElse(null); - if (blog == null){ + if (blog == null) { throw new NotFoundException("该博客不存在!"); } Blog b = new Blog(); - BeanUtils.copyProperties(blog,b); + BeanUtils.copyProperties(blog, b); b.setContent(MarkdownUtils.markdownToHtmlExtensions(b.getContent())); blogRepository.updateViews(id); return b; @@ -67,7 +66,7 @@ public class BlogServiceImpl implements BlogService public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { List predicates = new ArrayList<>(); if (!"".equals(blog.getTitle()) && blog.getTitle() != null) { - predicates.add(cb.like(root.get("title"), "%"+blog.getTitle()+"%")); + predicates.add(cb.like(root.get("title"), "%" + blog.getTitle() + "%")); } if (blog.getTypeId() != null) { predicates.add(cb.equal(root.get("type").get("id"), blog.getTypeId())); @@ -78,7 +77,7 @@ public class BlogServiceImpl implements BlogService cq.where(predicates.toArray(new Predicate[predicates.size()])); return null; } - },pageable); + }, pageable); } @Override @@ -93,20 +92,20 @@ public class BlogServiceImpl implements BlogService @Override public Predicate toPredicate(Root root, CriteriaQuery cq, CriteriaBuilder cb) { Join join = root.join("tags"); - return cb.equal(join.get("id"),tagId); + return cb.equal(join.get("id"), tagId); } }, pageable); } @Override public Page ListBlog(Pageable pageable, String query) { - return blogRepository.findByQuery(query,pageable); + return blogRepository.findByQuery(query, pageable); } @Override public List listRecommendBlogTop(Integer size) { - Sort sort = Sort.by(Sort.Direction.DESC,"updateTime"); - Pageable pageable = PageRequest.of(0,size,sort); + Sort sort = Sort.by(Sort.Direction.DESC, "updateTime"); + Pageable pageable = PageRequest.of(0, size, sort); return blogRepository.findTop(pageable); } @@ -127,8 +126,9 @@ public class BlogServiceImpl implements BlogService /** * 发布博客 - * (如何是新增博客,需要添加创建时间和修改时间、以及初始化浏览量view = 0) - * (如果是修改博客,需要添加修改时间) + * (如何是新增博客,需要添加创建时间和修改时间、以及初始化浏览量view = 0) + * (如果是修改博客,需要添加修改时间) + * * @param blog * @return */ @@ -141,6 +141,7 @@ public class BlogServiceImpl implements BlogService /** * 所谓的修改其实是查询+保存 + * * @param id * @param blog * @return @@ -150,12 +151,12 @@ public class BlogServiceImpl implements BlogService public Blog updateBlog(Long id, Blog blog) { Blog b = blogRepository.findById(id).orElse(null); //判断是否存在这条数据 - if(b == null){ + if (b == null) { throw new NotFoundException("该博客不存在"); } b.setUpdateTime(new Date()); //copy有值属性 不覆盖 - BeanUtils.copyProperties(blog,b, MyBeanUtils.getNullPropertyNames(blog)); + BeanUtils.copyProperties(blog, b, MyBeanUtils.getNullPropertyNames(blog)); return blogRepository.save(b); } diff --git a/src/main/java/cn/allms/service/impl/CommentServiceImpl.java b/src/main/java/cn/allms/service/impl/CommentServiceImpl.java index 3c989ee..ceccf6b 100644 --- a/src/main/java/cn/allms/service/impl/CommentServiceImpl.java +++ b/src/main/java/cn/allms/service/impl/CommentServiceImpl.java @@ -27,7 +27,7 @@ public class CommentServiceImpl implements CommentService { @Override public List listCommentByBlogId(Long blogId) { Sort sort = Sort.by("createTime"); - List comments = commentRepository.findByBlogIdAndParentCommentNull(blogId,sort); + List comments = commentRepository.findByBlogIdAndParentCommentNull(blogId, sort); return CommentUtil.eachComment(comments); } @@ -37,7 +37,7 @@ public class CommentServiceImpl implements CommentService { //回复: 如果有父级,需要将父级set进来,之后在保存 Long parentCommentId = comment.getParentComment().getId(); System.out.println(parentCommentId); - if(parentCommentId != -1){ + if (parentCommentId != -1) { comment.setParentComment(commentRepository.findById(parentCommentId).orElse(null)); } else { //发布评论: diff --git a/src/main/java/cn/allms/service/impl/TagServiceImpl.java b/src/main/java/cn/allms/service/impl/TagServiceImpl.java index 19c500a..60c1433 100644 --- a/src/main/java/cn/allms/service/impl/TagServiceImpl.java +++ b/src/main/java/cn/allms/service/impl/TagServiceImpl.java @@ -45,8 +45,8 @@ public class TagServiceImpl implements TagService { @Override public List ListTagTop(Integer size) { - Sort sort = Sort.by(Sort.Direction.DESC,"blogs.size"); - Pageable pageable = PageRequest.of(0,size,sort); + Sort sort = Sort.by(Sort.Direction.DESC, "blogs.size"); + Pageable pageable = PageRequest.of(0, size, sort); return tagRepository.findTop(pageable); } @@ -64,11 +64,11 @@ public class TagServiceImpl implements TagService { @Override public Tag updateTag(Long id, Tag tag) { Tag t = tagRepository.findById(id).orElse(null); - if(t==null){ + if (t == null) { throw new NotFoundException("不存在该标签"); } - BeanUtils.copyProperties(tag,t); + BeanUtils.copyProperties(tag, t); return tagRepository.save(t); } @@ -87,7 +87,7 @@ public class TagServiceImpl implements TagService { List list = new ArrayList<>(); if (!"".equals(ids) && ids != null) { String[] idarray = ids.split(","); - for (int i=0; i < idarray.length;i++) { + for (int i = 0; i < idarray.length; i++) { list.add(new Long(idarray[i])); } } diff --git a/src/main/java/cn/allms/service/impl/TypeServiceImpl.java b/src/main/java/cn/allms/service/impl/TypeServiceImpl.java index 904abbd..b3d9073 100644 --- a/src/main/java/cn/allms/service/impl/TypeServiceImpl.java +++ b/src/main/java/cn/allms/service/impl/TypeServiceImpl.java @@ -63,10 +63,10 @@ public class TypeServiceImpl implements TypeService { @Override public Type updateType(Long id, Type type) { Type t = typeRepository.findById(id).orElse(null); - if(t == null){ + if (t == null) { throw new NotFoundException("不存在该类型"); } - BeanUtils.copyProperties(type,t); + BeanUtils.copyProperties(type, t); return typeRepository.save(t); } diff --git a/src/main/java/cn/allms/util/CommentUtil.java b/src/main/java/cn/allms/util/CommentUtil.java index 820a7ff..8d66acd 100644 --- a/src/main/java/cn/allms/util/CommentUtil.java +++ b/src/main/java/cn/allms/util/CommentUtil.java @@ -12,6 +12,7 @@ import java.util.List; public class CommentUtil { /** * 循环每个顶级的评论节点 + * * @param comments * @return */ @@ -19,7 +20,7 @@ public class CommentUtil { List commentsView = new ArrayList<>(); for (Comment comment : comments) { Comment c = new Comment(); - BeanUtils.copyProperties(comment,c); + BeanUtils.copyProperties(comment, c); commentsView.add(c); } //合并评论的各层子代到第一级子代集合中 @@ -28,7 +29,6 @@ public class CommentUtil { } /** - * * @param comments root根节点,blog不为空的对象集合 * @return */ @@ -36,7 +36,7 @@ public class CommentUtil { for (Comment comment : comments) { List replys1 = comment.getReplyComments(); - for(Comment reply1 : replys1) { + for (Comment reply1 : replys1) { //循环迭代,找出子代,存放在tempReplys中 recursively(reply1); } @@ -46,20 +46,23 @@ public class CommentUtil { tempReplys = new ArrayList<>(); } } + //存放迭代找出的所有子代的集合 public static List tempReplys = new ArrayList<>(); + /** * 递归迭代,剥洋葱 + * * @param comment 被迭代的对象 * @return */ public static void recursively(Comment comment) { tempReplys.add(comment);//顶节点添加到临时存放集合 - if (comment.getReplyComments().size()>0) { + if (comment.getReplyComments().size() > 0) { List replys = comment.getReplyComments(); for (Comment reply : replys) { tempReplys.add(reply); - if (reply.getReplyComments().size()>0) { + if (reply.getReplyComments().size() > 0) { recursively(reply); } } diff --git a/src/main/java/cn/allms/util/MD5Utils.java b/src/main/java/cn/allms/util/MD5Utils.java index 47d5a8c..26913a4 100644 --- a/src/main/java/cn/allms/util/MD5Utils.java +++ b/src/main/java/cn/allms/util/MD5Utils.java @@ -10,14 +10,15 @@ public class MD5Utils { /** * MD5加密类 + * * @param str 要加密的字符串 - * @return 加密后的字符串 + * @return 加密后的字符串 */ - public static String code(String str){ + public static String code(String str) { try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); - byte[]byteDigest = md.digest(); + byte[] byteDigest = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < byteDigest.length; offset++) { diff --git a/src/main/java/cn/allms/util/MarkdownUtils.java b/src/main/java/cn/allms/util/MarkdownUtils.java index d8b95f0..bd5dfab 100644 --- a/src/main/java/cn/allms/util/MarkdownUtils.java +++ b/src/main/java/cn/allms/util/MarkdownUtils.java @@ -21,6 +21,7 @@ public class MarkdownUtils { /** * markdown格式转换成HTML格式 + * * @param markdown * @return */ @@ -34,6 +35,7 @@ public class MarkdownUtils { /** * 增加扩展[标题锚点,表格生成] * Markdown转换成HTML + * * @param markdown * @return */ diff --git a/src/main/java/cn/allms/util/MyBeanUtils.java b/src/main/java/cn/allms/util/MyBeanUtils.java index d8de038..f7cf112 100644 --- a/src/main/java/cn/allms/util/MyBeanUtils.java +++ b/src/main/java/cn/allms/util/MyBeanUtils.java @@ -15,12 +15,13 @@ public class MyBeanUtils { /** * 获取所有的属性值为空属性名数组 + * * @param source * @return */ public static String[] getNullPropertyNames(Object source) { BeanWrapper beanWrapper = new BeanWrapperImpl(source); - PropertyDescriptor[] pds = beanWrapper.getPropertyDescriptors(); + PropertyDescriptor[] pds = beanWrapper.getPropertyDescriptors(); List nullPropertyNames = new ArrayList<>(); for (PropertyDescriptor pd : pds) { String propertyName = pd.getName(); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index d10d5fc..c19acbd 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,13 +1,17 @@ +# 项目端口 +server: + port: 9420 + #数据库驱动mysql spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://103.153.100.47:3306/mx-blog?useUnicode=true&characterEncoding=utf-8&useSSL=false + url: jdbc:mysql://127.0.0.1:3306/mx-blog?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root - password: qfmx07229710 + password: 123456 jpa: hibernate: - ddl-auto: update + ddl-auto: create show-sql: false #日志打印 @@ -17,5 +21,4 @@ logging: cn.allms: debug file: name: log/blog-dev.log -server: - port: 9420 \ No newline at end of file + path: classpath:logback/logback-spring.xml \ No newline at end of file diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml index c58a570..3e786c4 100644 --- a/src/main/resources/application-pro.yml +++ b/src/main/resources/application-pro.yml @@ -15,7 +15,8 @@ logging: level: root: warn com.yrp: info - file: log/-blogpro.log + file: + name: log/-blogpro.log # 服务端口 server: diff --git a/src/main/resources/i18n/message.properties b/src/main/resources/i18n/message.properties index 367b13c..da7dcdc 100644 --- a/src/main/resources/i18n/message.properties +++ b/src/main/resources/i18n/message.properties @@ -5,14 +5,10 @@ index.type=\u5206\u7C7B index.tag=\u6807\u7B7E index.archive=\u5F52\u6863 index.aboutme=\u7AD9\u957F\u4FE1\u606F - - #\u5E95\u90E8\u5BFC\u822A\u680F\u4FE1\u606F index.email=\u90AE\u7BB1:qfmx520@163.com index.qq=QQ:745719461 index.about=\u4F5C\u8005\u662F\u4E00\u540Dspringboot\u7231\u597D\u8005,\u662F\u4E00\u540D\u6B63\u5728\u52AA\u529B\u594B\u6597\u7684\u5B66\u751F,\u4E3B\u8981\u5B66\u4E60JavaEE\u5F00\u53D1,Web\u524D\u7AEF\u7B49\u6280\u672F.\u4F5C\u8005\u662F\u4E2A\u559C\u6B22\u65C5\u884C\u7684\u5B69\u5B50,\u76EE\u6807\u662F\u6E38\u904D\u5168\u4E16\u754C\uFF01 index.copyright=copy @ 2020 - 2021 \u4f5c\u8005:\u6d45\u67ab\u6c90\u96ea \u6b64\u7ad9\u4ec5\u4f9b\u4e2a\u4eba\u6240\u6709 \u5982\u6709\u7591\u95ee\u8054\u7cfb\u4f5c\u8005 - - #\u4E8C\u7EF4\u7801\u626B\u7801\u9605\u8BFB\u5730\u5740 blog.serurl=127.0.0.1:80 \ No newline at end of file diff --git a/src/main/resources/i18n/message_en_US.properties b/src/main/resources/i18n/message_en_US.properties index 332d87f..d742b27 100644 --- a/src/main/resources/i18n/message_en_US.properties +++ b/src/main/resources/i18n/message_en_US.properties @@ -5,16 +5,10 @@ index.type=Type index.tag=Tag index.archive=Archive index.aboutme=About Me - - #\u5E95\u90E8\u5BFC\u822A\u680F\u4FE1\u606F index.email=Email:qfmx520@163.com index.qq=QQ:745719461 index.about=The author is a springboot enthusiast, a struggling student who mainly studies JavaEE development,Web front end and other technologies. index.copyright=copy @ 2020 - 2021 \u4f5c\u8005:\u6d45\u67ab\u6c90\u96ea \u6b64\u7ad9\u4ec5\u4f9b\u4e2a\u4eba\u6240\u6709 \u5982\u6709\u7591\u95ee\u8054\u7cfb\u4f5c\u8005 - - - #\u4E8C\u7EF4\u7801\u626B\u7801\u9605\u8BFB\u5730\u5740 - blog.serurl=172.20.10.6:8080 \ No newline at end of file diff --git a/src/main/resources/i18n/message_zh_CN.properties b/src/main/resources/i18n/message_zh_CN.properties index 1ad3f34..eba2f0d 100644 --- a/src/main/resources/i18n/message_zh_CN.properties +++ b/src/main/resources/i18n/message_zh_CN.properties @@ -5,13 +5,10 @@ index.type=\u5206\u7C7B index.tag=\u6807\u7B7E index.archive=\u5F52\u6863 index.aboutme=\u7AD9\u957F\u4FE1\u606F - - #\u5E95\u90E8\u5BFC\u822A\u680F\u4FE1\u606F index.email=\u90AE\u7BB1:qfmx520@163.com index.qq=QQ:745719461 index.about=\u4F5C\u8005\u662F\u4E00\u540Dspringboot\u7231\u597D\u8005,\u662F\u4E00\u540D\u6B63\u5728\u52AA\u529B\u594B\u6597\u7684\u5B66\u751F,\u4E3B\u8981\u5B66\u4E60JavaEE\u5F00\u53D1,Web\u524D\u7AEF\u7B49\u6280\u672F.\u4F5C\u8005\u662F\u4E2A\u559C\u6B22\u65C5\u884C\u7684\u5B69\u5B50,\u76EE\u6807\u662F\u6E38\u904D\u5168\u4E16\u754C\uFF01 index.copyright=copy @ 2020 - 2021 \u4f5c\u8005:\u6d45\u67ab\u6c90\u96ea \u6b64\u7ad9\u4ec5\u4f9b\u4e2a\u4eba\u6240\u6709 \u5982\u6709\u7591\u95ee\u8054\u7cfb\u4f5c\u8005 - #\u4E8C\u7EF4\u7801\u626B\u7801\u9605\u8BFB\u5730\u5740 blog.serurl=172.20.10.6:8080 \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback/logback-spring.xml similarity index 100% rename from src/main/resources/logback-spring.xml rename to src/main/resources/logback/logback-spring.xml diff --git a/src/main/resources/favicon.ico b/src/main/resources/static/favicon.ico similarity index 100% rename from src/main/resources/favicon.ico rename to src/main/resources/static/favicon.ico diff --git a/src/main/resources/templates/_fragments.html b/src/main/resources/templates/_fragments.html index 46f56c4..30cc164 100644 --- a/src/main/resources/templates/_fragments.html +++ b/src/main/resources/templates/_fragments.html @@ -7,7 +7,9 @@ 博客详情 - + @@ -19,8 +21,8 @@ - - + +