一:主要实现的功能
1.你配置数据库就一个配置文件就可以了啊 application.property
2.后台的界面就是博客的管理啊,标签的管理啊还有分类的管理
博客管理:
进行模糊查询、编辑、删除、新增操作
分类管理和标签管理都一样:(没啥新东西)
3.前台:
3.1首页就是关于博客什么的一些展示
比较重要的就是评论这一块儿:
当然最基本的就是找出所有的评论然后return到jsp中,但是这里有一个评论可能有回复的问题
这里用一个循环就可以了,
public String comments(Model model,@PathVariable Long blogId)
{
Sort sort=new Sort("createTime");
List<Comment> comment1=commentRepository.findByBlogIdAndParentCommentNull(blogId,sort);
List<Comment> comment2=new ArrayList<>();
for (Comment comment :comment1) {
Comment c=new Comment();
BeanUtils.copyProperties(comment,c);
comment2.add(c);
}
for (Comment cc:comment2
) {
List<Comment> c123 =cc.getReplyComments();
for (Comment ddd:c123
) {
recursively(ddd);
cc.setReplyComments(tempReplys);
tempReplys = new ArrayList<>();
}
}model.addAttribute("comments",comment2);
return "blog::commentList";
}
List<Comment> tempReplys=new ArrayList<>();private void recursively(Comment comment) {
tempReplys.add(comment);//顶节点添加到临时存放集合
if (comment.getReplyComments().size()>0) {
List<Comment> replys = comment.getReplyComments();
for (Comment reply : replys) {
tempReplys.add(reply);
if (reply.getReplyComments().size()>0) {
recursively(reply);
}
}
}
}
还有这个首页展示的分类、标签啊,搜的时候都是按照:(利用了分页查询封装好的方法来取出想要的数据【投机取巧了】)
Sort sort = new Sort(Sort.Direction.DESC,"blogs.size");
Pageable pageable = new PageRequest(0,size,sort);
return typeRepository.findTop(pageable);
这个findtop是在repository中自定义的。就是
List<Type> findTop(Pageable pageable);
3.2 归档
就是按照年份从数据库中找出找出对应的博客
3.3关于我
就是一个静态页面,放个图片,再放点个人的自我介绍
二:技术
springboot
jpa
thymeleaf
https://how2j.cn/k/springboot/springboot-thymeleat/1735.html //thymeleaf讲解
mysql
拦截器
aop的使用
@RequestParam
这个注解在Controller的时候喜欢用,作用是将请求参数绑定到你控制器的方法参数上面,就是接受从页面或者jsp传过来的参数。。 好像是如果是post方法传过来的话要加这个参数,否则的话不用加,,,好像是。
@PathVariable
我们可以直接在浏览器上面输入我们想要的id值,点击返回就会到注定的界面
或者在jsp页面中他返回路径也是带这个{id}的,然后给他赋值就可以了