Javaweb期末课设——雇员管理系统

时隔多日,终于有时间继续写博客,期末的复习时间占据了大部分时间。这次把期末小组共同完成的项目记录到这里,既是对自己知识的巩固,也是一个纪念意义。

雇员管理系统

实践环境

操作系统:Windows
JDK:1.8
Web服务器:Tomcat 8.0
数据库:Navicat For Mysql
浏览器:火狐浏览器

需求分析

此系统主要面对游客和管理员两类角色进行功能定位,基本定位如下:
对于游客:
(1)查看公司首页:游客进入系统可以直接浏览首页显示的所有公司新闻资讯、企业简介、公司服务。
(2)联系功能:游客进入网页页面后可以点击“联系我们”进行相互交流或留言。
对于系统的管理员:
(1)员工管理功能:管理员可以对企业的员工进行查看、搜索、修改、删除和增加,并进行对员工的离职和工资管理。
(2)部门管理功能:管理员可以查看左右部门的类别,进行查看、搜索、修改、删除和增加。
(3)客户端管理功能:管理员可以对前段游客发来的联系信息进行查看或删除。
(4)管理员管理功能:管理员可以对系统的管理员信息进行查看、修改密码、删除。

游客:
Javaweb期末课设——雇员管理系统

管理员:
Javaweb期末课设——雇员管理系统

数据库设计

(1)管理员实体(admin)图:
Javaweb期末课设——雇员管理系统
(2)部门实体(department)图:
Javaweb期末课设——雇员管理系统
(3)联系名单实体(guestbook)图:

Javaweb期末课设——雇员管理系统
(4)员工实体(person)图:
Javaweb期末课设——雇员管理系统

前端设计

前端页面的功能不大,主要都是静态页面和静态跳转,重心主要都放在后端的功能实现,这里先展示两个页面。

首页:
Javaweb期末课设——雇员管理系统

联系我们(前后端交互):

Javaweb期末课设——雇员管理系统

这里展示“联系我们”表单的核心代码:

<section>
		<div class="container auto">
			<div class="pic-tit">
					<div class="ab-tit">
						<h2><em>联系</em><em class="f-normal">我们</em></h2>
						<p class="s-font">CONTACT US</p>
					</div>
					<div class="v-line"></div>
				</div>
			<!-- <div style="width:100%;height:350px;border:#ccc solid 1px;font-size:12px" id="map"></div> -->
			<div class="auto clearfix">
				<div class="col-sm-4">
					<ul class="lx-dan">
						<li>电话:13067201052</li>
						<li>联系人:林先生</li>
						<li>邮箱:xxxxxx@163.com</li>
						<li>传真:xxxxxxxxxxxx</li>
						<li>地址:福建省厦门市集美区</li>
						<img src="${pageContext.request.contextPath }/static/img/bg_c.jpg">
					</ul>
				</div>
				<div class="col-sm-8">
					<form action = "${pageContext.request.contextPath}/AddGuestServlet" method = "post">  <!-- 这里做servlet交互 -->
						<input class="con" type="text" placeholder="姓名" name = "name" />
						<input class="con" type="text" placeholder="电话" name = "phone"/>
						<input class="con" type="text" placeholder="公司" name = "company"/>
						<input class="con" type="text" placeholder="地址" name = "address"/>
						<textarea type="text" placeholder="留言内容" name = "text"></textarea>
						<input class="submit" type="submit" value="提交" />
					</form>
				</div>
			</div>
		</div>
	</section>

(如果想要完整源码的可以私信我)

后端设计

后端管理系统由员工管理、部门管理、客户端管理组成,包括增删改查四个基本功能。由于篇幅太长,先拿员工管理来讲。

Javaweb期末课设——雇员管理系统
员工管理包括对员工的增加、员工信息的修改、员工离职、员工信息查询。

此后端系统采用三层架构:dao层(数据库操作处理)->service(逻辑层)->servlet(服务器响应)

Javaweb期末课设——雇员管理系统
1.domain包:

Person.java

package cn.edu.xit.domain;

public class Person {
	private int id;
	private String username;
	private String sex;
	private String phone;
	private String email;
	private double salary;
	private String department;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public double getSalary() {
		return salary;
	}
	public void setSalary(double salary) {
		this.salary = salary;
	}
	public String getDepartment() {
		return department;
	}
	public void setDepartment(String department) {
		this.department = department;
	}
	
}

2.dao包:

PersonDao.java

package cn.edu.xit.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.edu.xit.domain.Person;
import cn.edu.xit.util.DataSourceUtils;

public class PersonDao {
	
	//查询信息
	public List<Person> findAll() throws SQLException{
		QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from person";
		List<Person> person = queryRunner.query(sql, new BeanListHandler<Person>(Person.class));
		return person;
	}
	
	//根据username模糊查询
	public List<Person> findByUsername(String username) throws SQLException{

	}
	
	//增加员工
	public int addPerson(Person person) throws SQLException{
		QueryRunner queryRunner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "insert into person(id,username,sex,phone,email,salary,department) values(?,?,?,?,?,?,?)";
		int count = queryRunner.update(sql,person.getId(),person.getUsername(),person.getSex(),person.getPhone(),person.getEmail(),person.getSalary(),person.getDepartment());
		return count;
	}
	
	//解雇员工
	public int deletePerson(int id) throws SQLException{

	}
	
	//根据id更新员工姓名和电话
	public int updatePerson(Person person) throws SQLException{

	}
	
	//薪资处理
	public int updatePersonSalary(Person person) throws SQLException{

	}
	
}

这里展示增加员工和查询员工的功能,需要完整代码的可以私信本人~

3.service包:

PersonService.java

package cn.edu.xit.service;

import java.sql.SQLException;
import java.util.List;

import cn.edu.xit.dao.PersonDao;
import cn.edu.xit.domain.Person;

public class PersonService {
	private PersonDao personDao = new PersonDao();
	
	//查询所有信息
	public List<Person> findAll() throws SQLException{
		return personDao.findAll();
	}
	
	public List<Person> findByUsername(String username) throws SQLException{
		return personDao.findByUsername(username);
	}
	
	//删除
	public int deletePerson(int id) throws SQLException{
		return personDao.deletePerson(id);
	}
	
	//增加
	public int addPerson(Person person) throws SQLException{
		return personDao.addPerson(person);
	}
	
	//更新员工信息
	public int updatePerson(Person person) throws SQLException{
		return personDao.updatePerson(person);
	}
	
	//薪资处理
	public int updatePersonSalary(Person person) throws SQLException{
		return personDao.updatePersonSalary(person);
	}
	
}

4.servlet包:

addPersonServlet.java

package cn.edu.xit.PersonServlet;

import java.io.IOException;
import java.sql.SQLException;

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

import cn.edu.xit.domain.Person;
import cn.edu.xit.service.PersonService;

/**
 * Servlet implementation class updatePersonServlet
 */
@WebServlet("/addPersonServlet")
public class addPersonServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addPersonServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		int id = Integer.parseInt(request.getParameter("id"));
		String username = request.getParameter("username");
		String sex = request.getParameter("sex");
		String phone = request.getParameter("phone");
		String email = request.getParameter("email");
		double salary = Integer.parseInt(request.getParameter("salary"));
		String department = request.getParameter("department");
		Person person = new Person();
		person.setId(id);
		person.setUsername(username);
		person.setSex(sex);
		person.setPhone(phone);
		person.setEmail(email);
		person.setSalary(salary);
		person.setDepartment(department);
		
		PersonService personService = new PersonService();
		try{
			int result = personService.addPerson(person);
			if(result!=0){
				response.sendRedirect("FindPersonServlet2");
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}

FindPersonServlet.java

package cn.edu.xit.PersonServlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

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

import cn.edu.xit.domain.Person;
import cn.edu.xit.service.PersonService;

/**
 * Servlet implementation class FindPersonServlet
 */
@WebServlet("/FindPersonServlet")
public class FindPersonServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FindPersonServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		PersonService personService = new PersonService();
		try{
			List<Person> person = personService.findAll();
			if(person!=null){
				request.getSession().setAttribute("person", person);
				System.out.println("信息录入..");
				response.sendRedirect("FindDepartmentServlet");
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}

FindPersonServlet2.java(用于刷新信息)

package cn.edu.xit.PersonServlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

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

import cn.edu.xit.domain.Person;
import cn.edu.xit.service.PersonService;

/**
 * Servlet implementation class FindPersonServlet
 */
@WebServlet("/FindPersonServlet2")
public class FindPersonServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FindPersonServlet2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		PersonService personService = new PersonService();
		try{
			List<Person> person = personService.findAll();
			if(person!=null){
				request.getSession().setAttribute("person", person);
				System.out.println("信息录入..");
				response.sendRedirect("page/person/PersonInfo.jsp");
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}

PersonInfo.jsp(jsp显示员工信息),展示核心代码:

使用c:forEach标签遍历信息,jstl调用信息

<tbody id="tUser">
											<c:forEach items = "${person}" var = "person1">
											      <tr>
												<td>${person1.id}</td>
												<td>
													<a href="#">${person1.username}</a>
												</td>
												<td>${person1.sex}</td>
												<td>${person1.phone}</td>
												<td>${person1.email}</td>
												<td>${person1.department}</td>
											     <td><a href="${pageContext.request.contextPath}/DeletePersonServlet?id=${person1.id}" onclick="return confirm('确认删除')">删除</a>
					                                &nbsp;&nbsp;&nbsp;<a href="${pageContext.request.contextPath}/page/person/updatePerson.jsp?id=${person1.id}">修改</a>
					                             </td>
											   </tr>
											</c:forEach>
										</tbody>

jstl调用的时候需要加上此代码:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>

C3p0配置:

<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
	<default-config>
		<property name="driverClass">com.mysql.jdbc.Driver</property>
		<property name="jdbcUrl">jdbc:mysql://127.0.0.1/employeesystem?characterEncoding=utf8</property>
		<property name="user">root</property>
		<property name="password">swj93980</property>
	</default-config> 
</c3p0-config> 

登录功能:

Javaweb期末课设——雇员管理系统

Javaweb期末课设——雇员管理系统

后台页面采用iframe嵌套标签,欢迎页面使用session存取登录者的信息,再进行输出。

shouye.jsp

<%@ 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>首页</title>
</head>
<body style = "background-image: url('<%=request.getContextPath() %>/static/img/back.jpg');background-size:100%;">

<%
    String username = (String)session.getAttribute("adminname"); //得到登录者的信息
%>
<div>
<span style = "font-family: '微软雅黑';font-size:40px;margin-left:px;">
欢迎你,<%=username %>
</span>
</div>
</body>
</html>

如果需要源项目或者部分功能源码的可以私信我领取!


上一篇:阿里巴巴是如何打通 CMDB,实现就近访问的?


下一篇:oracleJava.sql.SQLException: 无效的列索引