springMVC+mybatis3+mysql实现的个人博客系统
今天给大家演示的是一款由springMVC+mybatis3+mysql实现的Java web个人博客管理系统,系统开发环境是eclipse,jdk7或8都可以,其他版本还没试过,tomcat是7.0,mysql版本不限,系统主要完成了前端博客信息浏览、搜索、评论,后台对博客分类、博客信息、评论审核、评论信息、友情链接、个人信息等功能的管理,整个系统包含完整源码和视频指导运行教程,在最下方有获取方式,
个人博客系统主要用于发表个人博客,记录个人生活日常,学习心得,技术分享等,供他人浏览,查阅,评论等。本系统结构如下:
代码已经上传github,下载地址: https://github.com/21503882/blogmany
(1)博主端:
登录模块:登入后台管理系统:首先进入登录页面,需要输入账号和密码。它会使用Shiro进行安全管理,对前台输入的密
码进行加密运算,然后与数据库中的进行比较。成功后才能登入后台系统。
博客管理模块: 博客管理功能分为写博客和博客信息管理。写博客是博主用来发表编写博客的,需要博客标题,然后选择博
客类型,最后将博客内容填入百度的富文本编辑器中,点击发布博客按钮即可发布博客。
博客类别管理模块:博主类别管理系统可以添加,修改和删除博客类型名称和排序序号。将会显示到首页的按日志类别区域。
游客可以从这里查找相关的感兴趣的博客内容
评论信息管理模块:评论管理功能分为评论审核和评论信息管理两部分。评论审核是当有游客或自己发表了评论之后,博主需
要在后台管理系统中审核评论。若想将此评论显示在页面上则点击审核通过,否则点击审核不通过。
个人信息管理模块:修改博主的个人信息,可以修改昵称,个性签名,可以添加个人头像,修改个人简介;
系统管理功能模块:友情链接管理,修改密码,刷新系统缓存和安全退出,友情链接管理可以添加,修改,删除友情链接网址
(2)游客端:
查询博客: 查询具体哪一篇博客
查看博客内容: 查看博客内容
查看博主个人信息:查看博主个人简介
发表评论: 可以评论具体某篇博客
友情链接: 查看友情链接
下面是部分演示截图:
package com.blog.controller;
import com.blog.entity.Blog;
import com.blog.lucene.BlogIndex;
import com.blog.service.BlogService;
import com.blog.service.CommentService;
import com.blog.util.StringUtil;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping({"/blog"})
public class BlogController
{
@Resource
private BlogService blogService;
@Resource
private CommentService commentService;
private BlogIndex blogIndex = new BlogIndex();
@RequestMapping({"/articles/{id}"})
public ModelAndView details(@PathVariable("id") Integer id, HttpServletRequest request)
throws Exception
{
ModelAndView mav = new ModelAndView();
Blog blog = this.blogService.findById(id);
String keyWords = blog.getKeyWord();
if (StringUtil.isNotEmpty(keyWords))
{
String[] arr = keyWords.split(" ");
mav.addObject("keyWords", StringUtil.filterWhite(Arrays.asList(arr)));
}
else
{
mav.addObject("keyWords", null);
}
mav.addObject("blog", blog);
blog.setClickHit(Integer.valueOf(blog.getClickHit().intValue() + 1));
this.blogService.update(blog);
Map<String, Object> map = new HashMap();
map.put("blogId", blog.getId());
map.put("state", Integer.valueOf(1));
mav.addObject("commentList", this.commentService.list(map));
mav.addObject("pageCode", genUpAndDownPageCode(this.blogService.getLastBlog(id), this.blogService.getNextBlog(id), request.getServletContext().getContextPath()));
mav.addObject("mainPage", "foreground/blog/view.jsp");
mav.addObject("pageTitle", blog.getTitle() + "_Java开源博客系统");
mav.setViewName("mainTemp");
return mav;
}
@RequestMapping({"/q"})
public ModelAndView search(@RequestParam(value="q", required=false) String q, @RequestParam(value="page", required=false) String page, HttpServletRequest request)
throws Exception
{
if (StringUtil.isEmpty(page)) {
page = "1";
}
ModelAndView mav = new ModelAndView();
mav.addObject("mainPage", "foreground/blog/result.jsp");
List<Blog> blogList = this.blogIndex.searchBlog(q.trim());
Integer toIndex = Integer.valueOf(blogList.size() >= Integer.parseInt(page) * 10 ? Integer.parseInt(page) * 10 : blogList.size());
mav.addObject("blogList", blogList.subList((Integer.parseInt(page) - 1) * 10, toIndex.intValue()));
mav.addObject("pageCode", genUpAndDownPageCode(Integer.valueOf(Integer.parseInt(page)), Integer.valueOf(blogList.size()), q, Integer.valueOf(10), request.getServletContext().getContextPath()));
mav.addObject("q", q);
mav.addObject("resultTotal", Integer.valueOf(blogList.size()));
mav.addObject("pageTitle", "搜索关键字'" + q + "'结果页面_Java开源博客系统");
mav.setViewName("mainTemp");
return mav;
}
private String genUpAndDownPageCode(Blog lastBlog, Blog nextBlog, String projectContext)
{
StringBuffer pageCode = new StringBuffer();
if ((lastBlog == null) || (lastBlog.getId() == null)) {
pageCode.append("<p>上一篇:没有了</p>");
} else {
pageCode.append("<p>上一篇:<a href='" + projectContext + "/blog/articles/" + lastBlog.getId() + ".html'>" + lastBlog.getTitle() + "</a></p>");
}
if ((nextBlog == null) || (nextBlog.getId() == null)) {
pageCode.append("<p>下一篇:没有了</p>");
} else {
pageCode.append("<p>下一篇:<a href='" + projectContext + "/blog/articles/" + nextBlog.getId() + ".html'>" + nextBlog.getTitle() + "</a></p>");
}
return pageCode.toString();
}
private String genUpAndDownPageCode(Integer page, Integer totalNum, String q, Integer pageSize, String projectContext)
{
long totalPage = totalNum.intValue() % pageSize.intValue() == 0 ? totalNum.intValue() / pageSize.intValue() : totalNum.intValue() / pageSize.intValue() + 1;
StringBuffer pageCode = new StringBuffer();
if (totalPage == 0L) {
return "";
}
pageCode.append("<nav>");
pageCode.append("<ul class='pager' >");
if (page.intValue() > 1) {
pageCode.append("<li><a href='" + projectContext + "/blog/q.html?page=" + (page.intValue() - 1) + "&q=" + q + "'>上一页</a></li>");
} else {
pageCode.append("<li class='disabled'><a href='#'>上一页</a></li>");
}
if (page.intValue() < totalPage) {
pageCode.append("<li><a href='" + projectContext + "/blog/q.html?page=" + (page.intValue() + 1) + "&q=" + q + "'>下一页</a></li>");
} else {
pageCode.append("<li class='disabled'><a href='#'>下一页</a></li>");
}
pageCode.append("</ul>");
pageCode.append("</nav>");
return pageCode.toString();
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Java个人博客系统后台登录页面</title>
<script src="${pageContext.request.contextPath}/static/bootstrap3/js/jquery-1.11.2.min.js"></script>
<STYLE>
body{
background: #ebebeb;
font-family: "Helvetica Neue","Hiragino Sans GB","Microsoft YaHei","\9ED1\4F53",Arial,sans-serif;
color: #222;
font-size: 12px;
}
*{padding: 0px;margin: 0px;}
.top_div{
background: #008ead;
width: 100%;
height: 400px;
}
.ipt{
border: 1px solid #d3d3d3;
padding: 10px 10px;
width: 290px;
border-radius: 4px;
padding-left: 35px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s
}
.ipt:focus{
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)
}
.u_logo{
background: url("${pageContext.request.contextPath}/static/images/username.png") no-repeat;
padding: 10px 10px;
position: absolute;
top: 43px;
left: 40px;
}
.p_logo{
background: url("${pageContext.request.contextPath}/static/images/password.png") no-repeat;
padding: 10px 10px;
position: absolute;
top: 12px;
left: 40px;
}
a{
text-decoration: none;
}
.tou{
background: url("${pageContext.request.contextPath}/static/images/tou.png") no-repeat;
width: 97px;
height: 92px;
position: absolute;
top: -87px;
left: 140px;
}
.left_hand{
background: url("${pageContext.request.contextPath}/static/images/left_hand.png") no-repeat;
width: 32px;
height: 37px;
position: absolute;
top: -38px;
left: 150px;
}
.right_hand{
background: url("${pageContext.request.contextPath}/static/images/right_hand.png") no-repeat;
width: 32px;
height: 37px;
position: absolute;
top: -38px;
right: -64px;
}
.initial_left_hand{
background: url("${pageContext.request.contextPath}/static/images/hand.png") no-repeat;
width: 30px;
height: 20px;
position: absolute;
top: -12px;
left: 100px;
}
.initial_right_hand{
background: url("${pageContext.request.contextPath}/static/images/hand.png") no-repeat;
width: 30px;
height: 20px;
position: absolute;
top: -12px;
right: -112px;
}
.left_handing{
background: url("${pageContext.request.contextPath}/static/images/left-handing.png") no-repeat;
width: 30px;
height: 20px;
position: absolute;
top: -24px;
left: 139px;
}
.right_handinging{
background: url("${pageContext.request.contextPath}/static/images/right_handing.png") no-repeat;
width: 30px;
height: 20px;
position: absolute;
top: -21px;
left: 210px;
}
</STYLE>
<SCRIPT type="text/javascript">
$(function(){
//得到焦点
$("#password").focus(function(){
$("#left_hand").animate({
left: "150",
top: " -38"
},{step: function(){
if(parseInt($("#left_hand").css("left"))>140){
$("#left_hand").attr("class","left_hand");
}
}}, 2000);
$("#right_hand").animate({
right: "-64",
top: "-38px"
},{step: function(){
if(parseInt($("#right_hand").css("right"))> -70){
$("#right_hand").attr("class","right_hand");
}
}}, 2000);
});
//失去焦点
$("#password").blur(function(){
$("#left_hand").attr("class","initial_left_hand");
$("#left_hand").attr("style","left:100px;top:-12px;");
$("#right_hand").attr("class","initial_right_hand");
$("#right_hand").attr("style","right:-112px;top:-12px");
});
});
function checkForm(){
var userName=$("#userName").val();
var password=$("#password").val();
if(userName==null||userName==""){
$("#error").html("用户名不能为空!");
return false;
}
if(password==null||password==""){
$("#error").html("密码不能为空!");
return false;
}
return true;
}
</SCRIPT>
</head>
<body>
<DIV class="top_div">
</DIV>
<form action="${pageContext.request.contextPath}/blogger/login.do" method="post" οnsubmit="return checkForm()">
<DIV style="background: rgb(255, 255, 255); margin: -100px auto auto; border: 1px solid rgb(231, 231, 231); border-image: none; width: 400px; height: 200px; text-align: center;">
<DIV style="width: 165px; height: 96px; position: absolute;">
<DIV class="tou">
</DIV>
<DIV class="initial_left_hand" id="left_hand">
</DIV>
<DIV class="initial_right_hand" id="right_hand">
</DIV>
</DIV>
<P style="padding: 30px 0px 10px; position: relative;">
<SPAN class="u_logo"></SPAN>
<INPUT id="userName" name="userName" class="ipt" type="text" placeholder="请输入用户名" value="${blogger.userName }">
</P>
<P style="position: relative;">
<SPAN class="p_logo"></SPAN>
<INPUT id="password" name="password" class="ipt" type="password" placeholder="请输入密码" value="${blogger.password }">
</P>
<DIV style="height: 50px; line-height: 50px; margin-top: 30px; border-top-color: rgb(231, 231, 231); border-top-width: 1px; border-top-style: solid;">
<P style="margin: 0px 35px 20px 45px;">
<SPAN style="float: left;"><a href="${pageContext.request.contextPath}/index.html">Java个人博客系统</a></SPAN>
<span><font color="red" id="error">${errorInfo }</font></span>
<SPAN style="float: right;">
<input type="submit" style="background: rgb(0, 142, 173); padding: 7px 10px; border-radius: 4px; border: 1px solid rgb(26, 117, 152); border-image: none; color: rgb(255, 255, 255); font-weight: bold;" value="登录"/>
</SPAN>
</P>
</DIV>
</DIV>
</form>
</body>
</html>