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.核心代码
登录页面:
后台登录 if(window.top !== window.self){ window.top.location = window.location;}pc
欢迎使用
登录控制器类:
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;@Autowiredprivate Manager manager;@Autowiredprivate 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 {@Overridepublic void save(Manager arg) {daoImpl.save(arg);}@Overridepublic Manager find(String arg) throws Exception {//return null;}@Overridepublic List findAll(String arg) {return daoImpl.findAll();}@Overridepublic 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 implements ManagerDao {@Overridepublic List findAll() {return (List) ht.find("from Manager");}}
6.项目截图
登录页面
首页
添加员工
个人信息
系统设置