1.项目源代码结构:
:
2.项目运行截图
登录界面运行截图:
登陆成功操作截图:如果输入管理员正确账号和密码,进入主界面则出现以下截图
查看员工的所有数据:
查询:
添加员工:
删除员工:
岗位界面截图:
岗位查询:
岗位修改:
岗位添加:
3.系统功能介绍
4.SQL文件
/*
SQLyog Ultimate v12.08 (32 bit)
MySQL - 5.5.15 : Database - office
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`office` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `office`;
/*Table structure for table `t_contract` */
DROP TABLE IF EXISTS `t_contract`;
CREATE TABLE `t_contract` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`contractno` varchar(100) DEFAULT NULL,
`contractdate` datetime DEFAULT NULL,
`state` varchar(10) DEFAULT NULL,
`staffid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
/*Data for the table `t_contract` */
insert into `t_contract`(`id`,`contractno`,`contractdate`,`state`,`staffid`) values (1,'0001','2022-08-10 00:00:00','变更',1),(2,'0002','2022-01-15 00:00:00','解除',2);
/*Table structure for table `t_deptype` */
DROP TABLE IF EXISTS `t_deptype`;
CREATE TABLE `t_deptype` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`depname` varchar(50) DEFAULT NULL,
`depdesc` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*Data for the table `t_deptype` */
insert into `t_deptype`(`id`,`depname`,`depdesc`) values (1,'人事部','人事管工作'),(2,'仓储部','仓库物品及物流管理部门'),(3,'研发部','研发部');
/*Table structure for table `t_posttype` */
DROP TABLE IF EXISTS `t_posttype`;
CREATE TABLE `t_posttype` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`postname` varchar(50) DEFAULT NULL,
`postdesc` varchar(50) DEFAULT NULL,
`postlevel` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
/*Data for the table `t_posttype` */
insert into `t_posttype`(`id`,`postname`,`postdesc`,`postlevel`) values (1,'人事副部长','人事副部长','1'),(2,'仓储物管','仓库物管负责人','组长');
/*Table structure for table `t_staff` */
DROP TABLE IF EXISTS `t_staff`;
CREATE TABLE `t_staff` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`staffname` varchar(100) DEFAULT NULL,
`identify` varchar(100) DEFAULT NULL,
`sex` varchar(10) DEFAULT NULL,
`postid` int(11) DEFAULT NULL,
`depid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*Data for the table `t_staff` */
insert into `t_staff`(`id`,`staffname`,`identify`,`sex`,`postid`,`depid`) values (1,'陈老板','430621199904250539','男',1,1),(2,'张工','4320554120524112','男',2,2),(3,'刘老哥','430918851255420','男',2,2);
/*Table structure for table `t_user` */
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,
`userid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*Data for the table `t_user` */
insert into `t_user`(`id`,`username`,`password`,`userid`) values (1,'wenber','123',1);
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
5.部分代码展示
Staff.java
package com.wenber.entity;
/**
* 员工对象
* @author Code人生
*
*/
public class Staff {
int id;
String staffname;
String identify;
String sex;
DeptType dept;
PostType post;
public Staff() {
}
public Staff( String staffname, String identify, String sex) {
super();
this.staffname = staffname;
this.identify = identify;
this.sex = sex;
}
public Staff(String staffname, String identify, String sex, DeptType dept, PostType post) {
super();
this.staffname = staffname;
this.identify = identify;
this.sex = sex;
this.dept = dept;
this.post = post;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getStaffname() {
return staffname;
}
public void setStaffname(String staffname) {
this.staffname = staffname;
}
public String getIdentify() {
return identify;
}
public void setIdentify(String identify) {
this.identify = identify;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public DeptType getDept() {
return dept;
}
public void setDept(DeptType dept) {
this.dept = dept;
}
public PostType getPost() {
return post;
}
public void setPost(PostType post) {
this.post = post;
}
@Override
public String toString() {
return staffname + "=" + dept.getDepName() + "=" + post.getPostName();
}
}
PostType.java
package com.wenber.entity;
/**
* 岗位
* @author Code人生
*
*/
public class PostType {
private int id;
private String postName;
private String postDesc;
private String postLevel;
public PostType() {
}
public PostType(String postName) {
this.postName = postName;
}
public PostType(String postName, String postDesc, String postLevel) {
super();
this.postName = postName;
this.postDesc = postDesc;
this.postLevel = postLevel;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPostName() {
return postName;
}
public void setPostName(String postName) {
this.postName = postName;
}
public String getPostDesc() {
return postDesc;
}
public void setPostDesc(String postDesc) {
this.postDesc = postDesc;
}
public String getPostLevel() {
return postLevel;
}
public void setPostLevel(String postLevel) {
this.postLevel = postLevel;
}
@Override
public String toString() {
return postName ;
}
}
StaffDao.java
package com.wenber.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import com.yyw.entity.DeptType;
import com.yyw.entity.PostType;
import com.yyw.entity.Staff;
import com.yyw.utils.DBUtils;
/**
* 员工数据处理层
* @author Code人生
*
*/
public class StaffDao {
/**
* 查询
* @param id 员工
* @return 对象
*/
public Staff findStaffByID(int id){
Connection conn=DBUtils.getConnection();
String sql="select * from t_staff ts left join t_posttype post on post.id=ts.postid left join t_deptype dept on dept.id=ts.depid where ts.id="+id;
Staff staff=null;
try {
Statement stat=conn.createStatement();
//执行SQL
ResultSet rs=stat.executeQuery(sql);
if (rs.next()) {
String staffname=rs.getString("staffname");
String identify=rs.getString("identify");
String sex=rs.getString("sex");
PostType post=new PostType(rs.getString("postname"));
DeptType dept=new DeptType(rs.getString("depname"));
//组装
staff=new Staff(staffname, identify, sex, dept, post);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBUtils.closeConn(conn);
}
return staff;
}
/**
* 修改数据
* @param staff
* @return
*/
public int editStaff(Staff staff){
Connection conn=DBUtils.getConnection();
String sql="update t_staff set staffname=?,identify=?,sex=?,depid=?,postid=? where id=?";
int row=0;
QueryRunner qr=new QueryRunner();
try {
row=qr.update(conn, sql,staff.getStaffname(),staff.getIdentify(),staff.getSex(),staff.getDept().getId(),staff.getPost().getId(),staff.getId());
} catch (Exception e) {
e.printStackTrace();
}finally{
DBUtils.closeConn(conn);
}
return row;
}
/**
* 保存数据
* @param staff
* @return
*/
public int saveStaff(Staff staff){
Connection conn=DBUtils.getConnection();
String sql="insert into t_staff(staffname,identify,sex,depid,postid) values(?,?,?,?,?)";
int row=0;
QueryRunner qr=new QueryRunner();
try {
row=qr.update(conn, sql, staff.getStaffname(),staff.getIdentify(),staff.getSex(),staff.getDept().getId(),staff.getPost().getId());
} catch (Exception e) {
e.printStackTrace();
}finally{
DBUtils.closeConn(conn);
}
return row;
}
/**
* 根据输入ID删除对象
* @param id 员工ID
* @return 删除的行数
*/
public int removeStaffById(int id){
Connection conn=DBUtils.getConnection();
String sql="delete from t_staff where id=?";
QueryRunner qr=new QueryRunner();
int row=0;
try {
row=qr.update(conn, sql, id);
} catch (Exception e) {
e.printStackTrace();
}
return row;
}
/**
* 查询员工 没有签合同
* @return
*/
public List<Staff> findStaffListForContract(){
Connection conn=DBUtils.getConnection();
String sql="select * from t_staff ts left join t_posttype post on post.id=ts.postid left join t_deptype dept on dept.id=ts.depid left join t_contract tc on tc.staffid=ts.id where contractno is null";
System.out.println(sql);
//查询器
List<Staff> staffList=new ArrayList<Staff>();
try {
Statement stat=conn.createStatement();
//执行SQL
ResultSet rs=stat.executeQuery(sql);
while (rs.next()) {
String staffname=rs.getString("staffname");
String identify=rs.getString("identify");
String sex=rs.getString("sex");
PostType post=new PostType(rs.getString("postname"));
DeptType dept=new DeptType(rs.getString("depname"));
//组装
Staff staff=new Staff(staffname, identify, sex, dept, post);
staff.setId(rs.getInt("ts.id"));
staffList.add(staff);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
//执行完成关闭连接
DBUtils.closeConn(conn);
}
return staffList;
}
/**
* 重载查询方法
* @return
*/
public List<Staff> findStaffList(){
return this.findStaffList("", "","");
}
/**
* 取得信息表
* @return 返回列表
*/
public List<Staff> findStaffList(String id,String name,String idcard){
Connection conn=DBUtils.getConnection();
String sql="select * from t_staff ts left join t_posttype post on post.id=ts.postid left join t_deptype dept on dept.id=ts.depid where 1=1";//拼接SQL的小技巧
String condition="";
if(name!=null && !name.equals("")){
condition+=" and staffname='"+name+"'";
}
if(idcard!=null && !idcard.equals("")){
condition+=" and identify='"+idcard+"'";
}
if(id!=null && !id.equals("")){
condition+=" and ts.id="+Integer.parseInt(id);
}
//将条件拼在SQL的最后
sql+=condition;
System.out.println(sql);
//查询器
List<Staff> staffList=new ArrayList<Staff>();
try {
Statement stat=conn.createStatement();
//执行SQL
ResultSet rs=stat.executeQuery(sql);
while (rs.next()) {
String staffname=rs.getString("staffname");
String identify=rs.getString("identify");
String sex=rs.getString("sex");
PostType post=new PostType(rs.getString("postname"));
DeptType dept=new DeptType(rs.getString("depname"));
//组装
Staff staff=new Staff(staffname, identify, sex, dept, post);
staff.setId(rs.getInt("ts.id"));
staffList.add(staff);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
//执行完成关闭连接
DBUtils.closeConn(conn);
}
return staffList;
}
}