1.项目需求

使用Javaweb+MySQL实现一个员工管理系统,能对员工进行增删改查,使用SSH框架开发。

2.数据表设计

manager(管理员表)

CREATE TABLE `manager` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`head` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

employee(员工表)

CREATE TABLE `employee` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ranking` int(11) DEFAULT NULL,
`real_name` varchar(255) DEFAULT NULL,
`icon_address` varchar(255) DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`experience_value` int(11) DEFAULT NULL,
`experience_bar` varchar(255) DEFAULT NULL,
`stars_value` int(11) DEFAULT NULL,
`level` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

systeminfo(系统表)

CREATE TABLE `systeminfo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`system_title` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

3.架构设计

使用SSH框架开发,使用MySQL数据库。

4.项目代码目录结构

action:控制器包

dao:数据操作接口

dao.Impl:数据操作实现工具包

po:实体类包

service:服务包

utils:工具类包

5.核心代码

登录页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">


<title>后台登录</title>
<link rel="shortcut icon" href="favicon.ico">
<link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">

<link href="css/animate.css" rel="stylesheet">
<link href="css/style.css?v=4.1.0" rel="stylesheet">
<!--[if lt IE 9]>
<meta http-equiv="refresh" content="0;ie.html" />
<![endif]-->
<script>if(window.top !== window.self){ window.top.location = window.location;}</script>
</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen animated fadeInDown">
<div>
<div>
<h1 class="logo-name">pc</h1>
</div>
<h3>欢迎使用</h3>

<form class="m-t" role="form" action="login_login.action">
<div class="form-group">
<input type="text" name="uname" class="form-control"
placeholder="用户名" required="true">
</div>
<div class="form-group">
<input type="password" name="upass" class="form-control"
placeholder="密码" required="true">
</div>
<button type="submit" class="btn btn-primary block full-width m-b">
</button>

</p>

</form>
</div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<script type="text/javascript"
src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<!--统计代码,可删除-->

</body>

</html>

登录控制器类:

package cn.lxy.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import cn.lxy.po.Manager;
import cn.lxy.service.ManagerServc;

public class LoginAction extends BasicAction {
private String uname;
private String upass;
private int usertype;
@Autowired
private Manager manager;
@Autowired
private ManagerServc managerServc;
private String resultinfo;

public void hello() {
HttpServletRequest request = ServletActionContext.getRequest();
String id = request.getParameter("id");
System.out.println(id);
System.out.println("hello");
}

public String login() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
String uname = request.getParameter("uname");
String upass = request.getParameter("upass");
manager = managerServc.login(uname, upass);
if (manager.getName() != null) {
this.getSesion().put("Manager", manager);
return "login";
} else {
return "pleaselogin";
}
}

public String tomain() {
if (manager == null) {
return "pleaselogin";
} else {
return "tomain";
}
}

public String logout() {
this.getSesion().clear();
return "pleaselogin";
}

public String getUname() {
return uname;
}

public void setUname(String uname) {
this.uname = uname;
}

public String getUpass() {
return upass;
}

public void setUpass(String upass) {
this.upass = upass;
}

public String getResultinfo() {
return resultinfo;
}

public void setResultinfo(String resultinfo) {
this.resultinfo = resultinfo;
}

}

登录service类:

package cn.lxy.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.lxy.dao.Impl.ManagerDaoImpl;
import cn.lxy.po.Manager;

@Transactional
@Service(value="managerServc")
public class ManagerServc extends CommonSevc<Manager, ManagerDaoImpl> {

@Override
public void save(Manager arg) {
daoImpl.save(arg);
}

@Override
public Manager find(String arg) throws Exception {
//
return null;
}

@Override
public List<Manager> findAll(String arg) {
return daoImpl.findAll();
}

@Override
public void delete(Manager arg) {
//

}

public Manager login(String arg1,String arg2) throws Exception {
return (Manager) this.getEntity.login("Manager", "username = '"+arg1+"' and password = '"+arg2+"'", Manager.class);
}


}

登录dao类:

package cn.lxy.dao.Impl;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.lxy.dao.ManagerDao;
import cn.lxy.po.Manager;

@Component(value="managerDaoImpl")
public class ManagerDaoImpl extends CommonDaoImpl<Manager> implements ManagerDao {

@Override
public List<Manager> findAll() {
return (List<Manager>) ht.find("from Manager");
}

}

6.项目截图

登录页面

javaweb项目案例:员工管理系统_数据库

 首页

javaweb项目案例:员工管理系统_mysql_02

添加员工

javaweb项目案例:员工管理系统_css_03

个人信息

javaweb项目案例:员工管理系统_html_04

 系统设置

javaweb项目案例:员工管理系统_数据库_05

关注个人微信公众号:小诸葛的博客,回复202可免费获取源代码。