基于SSM开发的个人博客管理系统

10042基于SSM开发的个人博客管理系统

代码:
想-要-的-直-JIE-私–LIAO, 晚 -上-统-一-回-复

技术
Spring + SpringMVC + Mybatis

工具
eclipse + tomact + mysql + jdk

功能详情

前台功能 后台功能
首页 常用操作
关于博主 博客管理
登录后台 博客类别管理
最新博客 评论管理
友情链接 个人信息管理
搜索框 系统管理

系统相关截图

● 系统首页

基于SSM开发的个人博客管理系统_第1张图片
● 写博客

基于SSM开发的个人博客管理系统_第2张图片
package com.jxust.svsh.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jxust.svsh.dao.PersonDAO;
import com.jxust.svsh.entity.Person;

@Transactional
@Service
public class PersonService {

@Autowired
public PersonDAO personDAO;

/**
 * 添加
 * @param person
 */
public void addPerson(Person person) {
	personDAO.addPerson(person);
}
/**
 * 根据id查询
 * @param id
 * @return
 */
public Person getPersonById(String id){
	return personDAO.getPersonById(id);
}
/**
 * 更新
 * @param person
 */
public void updatePerson(Person person) {
	personDAO.updatePerson(person);
}
/**
 * 删除
 * @param id
 */
public void deletePersonById(String  id) {
	personDAO.deletePersonById(id);
}
/**
 * 查询所有
 * @return
 */
public List getPersons() {
	return personDAO.getPersons();
}

}package com.jxust.svsh.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.jxust.svsh.entity.Person;

@Repository
public class PersonDAO {

@Resource
private SessionFactory sessionFactory;

private Session getSession() {
	return sessionFactory.getCurrentSession();
}
/**
 * 根据id查询
 * @param id
 * @return
 */
public Person getPersonById(String id) {
	return (Person) this.getSession().createQuery("from Person where id=?").setParameter(0, id).uniqueResult();
}
/**
 * 添加
 * @param person
 */
public void addPerson(Person person) {
	this.getSession().save(person);
}
/**
 * 更新
 * @param person
 */
public void updatePerson(Person person) {
	this.getSession().update(person);
}
/**
 * 删除
 * @param id
 */
public void deletePersonById(String id) {
	this.getSession().createQuery("delete Person where id=?").setParameter(0, id).executeUpdate();
}
/**
 * 查询所有
 * @return
 */
@SuppressWarnings("unchecked")
public List getPersons() {
	return this.getSession().createCriteria(Person.class).list();
}

}package com.jxust.svsh.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.jxust.svsh.entity.Person;
import com.jxust.svsh.service.PersonService;

/**

  • controller

  • @author //标识它是一个控制器

  • @Date2016年12月9日上午11:25:40
    */
    @SessionAttributes(value = “username”)
    @Controller //使用该注解标志它是一个控制器
    @RequestMapping(value = “/person”)
    public class PersonController {

    @Autowired
    public PersonService personService;

    /**

    • 登录请求,失败返回error.jsp
    • @param username
    • @param password
    • @return
      /
      @RequestMapping("/login")
      public String dologin(String username, String password, Map map) {
      if (username.equals(“admin”) && password.equals(“admin”)) {
      map.put(“username”, username);//存放在request请求域中
      /
      *
      * 类上加上@SessionAttributes({“username”}) 同时也会存放在 session域中
      * @SessionAttributes 除了可以通过属性名指定需要存放到会话中的属性外(使用的是value属性值)
      * 还可以通过模型属性的对象类型指定哪些模型属性需要放到会话中(实际上使用的是types属性值),
      */
      return “frame”;
      }
      return “error”;
      }

    /**

    • 保存添加的数据
    • @param person
    • @return
      */
      @RequestMapping(value = “/saveperson”)
      public String saveperson(Person person) {
      personService.addPerson(person);
      return “redirect:main”;
      }

    /**

    • 跳转到添加页面

    • savepage.jsp

    • @return
      */
      @RequestMapping(value = “/addperson”)
      public String saveperson() {

      return “savepage”;
      }

    /**

    • 删除一条数据
    • @param id
    • @return
      */
      @RequestMapping(value = “/deletePersonById”)
      public String deletePersonById(@RequestParam(value = “id”) String id) {
      System.out.println(“删除单个”);
      personService.deletePersonById(id);
      return “redirect:main”;
      }

    /**

    • 跳转到更新页面,回显数据
    • editpage.jsp
    • @param id
    • @param model 使用的Model保存回显数据
    • @return
      */
      @RequestMapping(value = “/doupdate”)
      public String doupdate(@RequestParam(value = “id”) String id, Model model) {
      model.addAttribute(“person”, personService.getPersonById(id));
      return “editpage”;
      }

    /**

    • 更新数据
    • @param person
    • @return
      */
      @RequestMapping(value = “/updateperson”)
      public String updateperson(Person person) {
      System.out.println(person.toString());
      personService.updatePerson(person);
      return “redirect:main”;
      }

    /**

    • 查询所有人员信息
    • @param map 使用的是map保存回显数据
    • @return
      */
      @RequestMapping(value = “/main”)
      public String mian(Map map) {
      map.put(“personlist”, personService.getPersons());
      /*遍历集合,查看查询到的数据
      • List lists = personService.getPersons();
      • Iterator it = lists.iterator();
      • while(it.hasNext()){
      •  Person p =it.next();
        
      •  System.out.println(p.toString());
        
      • }
        */
        return “main”;
        }
        }
        package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.daoImpl.DeptDaoImpl;
import com.daoImpl.EmploeDaoImpl;
import com.daoImpl.PostDaoImpl;
import com.entity.Dept;
import com.entity.Emploe;
import com.entity.Post;

public class EmploeDetail extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	String eid = request.getParameter("eid");
	EmploeDaoImpl edi = new EmploeDaoImpl();
	Emploe emploe = edi.getEmploeById(Integer.parseInt(eid));
	DeptDaoImpl ddi = new DeptDaoImpl();
	Dept dept = ddi.getDeptById(emploe.getDid());
	String dname =dept.getDname();
	request.getSession().setAttribute("dname",dname);
	PostDaoImpl pdi = new PostDaoImpl();
	Post post = pdi.getPostById(emploe.getPid());
	String pname =post.getPname();
	request.getSession().setAttribute("pname",pname);
	request.getSession().setAttribute("emploe", emploe);
	response.sendRedirect("manager/emploe_detail.jsp");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	this.doGet(request, response);
}

}package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.daoImpl.EmploeDaoImpl;

public class EmploeLog_off extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	EmploeDaoImpl edi = new EmploeDaoImpl();
	String eid = request.getParameter("eid");
	boolean flag = edi.remove(Integer.parseInt(eid));
	if(flag){
		response.sendRedirect("index.jsp");
	}
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	this.doGet(request, response);
}

}package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.daoImpl.MessageDaoImpl;
import com.entity.Message;

public class EmploeNewsAdd extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	String mtitle = request.getParameter("mtitle");
	String muser = request.getParameter("muser");
	String mcontent = request.getParameter("mcontent");
	Date d = new Date();
	String mtime = d.toLocaleString();
	System.out.println(mtime);
	Message msg = new Message();
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	try {
		msg.setMtime(sdf.parse(mtime));
	} catch (ParseException e) {
		e.printStackTrace();
	}
	msg.setMtitle(mtitle);
	msg.setMcontent(mcontent);
	msg.setMuser(muser);
	msg.setMstatus(1);
	MessageDaoImpl mdi = new MessageDaoImpl();
	boolean flag = mdi.addMessage(msg);
	System.out.println(flag);
	if(flag){
		request.getSession().setAttribute("Message", msg);
		response.sendRedirect("EmploeNewTable");
	}else{
		response.sendRedirect("emploe/news_add.jsp");
	}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
	this.doGet(request, response);
}

}

你可能感兴趣的:(java项目,java,java,mysql,ssm,博客管理系统,管理系统)