基于SSH实现员工管理系统

项目源码:https://github.com/joshul/ssh_1

软件环境

win7、mysql5.5、jdk1.8、tomcat 8

开发工具

idea + mysql Workbench

功能简述
  1. 首先是登陆页面,管理员登陆权限设定只能是人事部员工的才可以登陆。
  2. 登陆只能可以在部门管理栏和员工管理,部门管理可以进行添加新部门、删除旧部门和编辑操作。
  3. 员工管理同样也可以进行编辑、删除、添加新员工。
使用到的技术
  • Spring
  • Struts2
  • hibernate
  • c3p0连接池
  • jsp
页面展示:
登录页
详情页
详情页
编辑页面
数据表
代码实现过程
1. 业务分析

需要有一个登陆页面,输入姓名和密码可实现登陆。进去到后台管理页面,页面中有人力资源管理部分,分别有部门管理和员工管理,当点击部门管理是会跳转到显示所有部门的页面,在这个页面中我们可以在这里添加或删除部门或修改,当然也具有分页的显示的功能。员工管理具有和部门管理一样的功能,也可以对员工进行添加、删除、编辑的管理,在添加员工栏中会有选择所属部门的选型框。

2. 编码过程

2.1建立工程导入jar包

jar包

2.2建立工程目录


工程目录

2.2导入工程所需配置文件

  • 2.2.1
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        <!-- Spring的框架的核心监听器  -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <filter>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>
<!-- Struts2的框架的核心过滤器的配置 -->
    <filter>
        <filter-name>struts</filter-name>
        <!-- FilterDispatcher是struts2.0.x到2.1.2版本的核心过滤器.StrutsPrepareAndExecuteFilter是自2.1.3开始就替代了FilterDispatcher.-->
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <package name="ssh"  extends="struts-default" namespace="/">
        <!-- 注册拦截器 -->
        <interceptors>
            <interceptor name="AuthInterceptor" class="com.muke.employee.interceptor.AuthInterceptor"></interceptor>
            <!-- 自定义一个拦截器栈 myStack:含默认的拦截器:defaultStack 和 自己创建的拦截器:AuthInterceptor -->
            <interceptor-stack name="myStack">
                <interceptor-ref name="defaultStack"></interceptor-ref>
                <interceptor-ref name="AuthInterceptor">
                    <!--  AuthInterceptor继承 MethodFilterInterceptor类,所以可以使用excludeMethods将某些方法排除在拦截器之外-->
                    <param name="excludeMethods">login</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>
        
        <action name="employee_*" class="employeeAction" method="{1}">
            <!-- 使用在/toIndex.jsp页面中使用top.window.location.href="/index.jsp"跳出frame框架 -->
            <result name="input">/toIndex.jsp</result>
            <result name="login">/toIndex.jsp</result>
            <result name="success" type="redirect">/frame.jsp</result>
            <result name="findAll">/jsp/employee/list.jsp</result>
            <result name="saveUI">/jsp/employee/add.jsp</result>
            <result name="saveSuccess" type="redirectAction">employee_findAll.action</result>
            <result name="editSuccess">/jsp/employee/edit.jsp</result>
            <result name="updateSuccess" type="redirectAction">employee_findAll.action</result>
            <result name="deleteSuccess" type="redirectAction">employee_findAll.action</result>
            <interceptor-ref name="myStack"></interceptor-ref>
        </action>
        <action name="department_*" class="departmentAction" method="{1}">
            <!-- 使用在/toIndex.jsp页面中使用top.window.location.href="/index.jsp"跳出frame框架 -->
            <result name="login">/toIndex.jsp</result>
            <result name="findAll">/jsp/department/list.jsp</result>
            <result name="saveUI">/jsp/department/add.jsp</result>
            <result name="saveSuccess" type="redirectAction">department_findAll.action</result>
            <result name="updateSuccess" type="redirectAction">department_findAll.action</result>
            <result name="deleteSuccess" type="redirectAction">department_findAll.action</result>
            <result name="editSuccess">/jsp/department/edit.jsp</result>
            <interceptor-ref name="myStack"></interceptor-ref>
        </action>
    </package>
    
</struts>

struts.xml

jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssh_employee
jdbc.username=root
jdbc.password=root

jdbc.properties

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    
    <!-- 引入外部的属性文件:连接池属性 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    
    <!-- 配置连接池 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driverClass}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>
    
    <!-- 配置Hibernate的相关属性 -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!-- 注入连接池 -->
        <property name="dataSource" ref="dataSource"/>
        <!-- 配置Hibernate的属性 -->
        <property name="hibernateProperties">
            <props>
                <!-- 设置dialect方言为MySQL -->
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <!-- 是否显示sql语句:true -->
                <prop key="hibernate.show_sql">true</prop>
                <!-- 是否格式化sql语句:true -->
                <prop key="hibernate.fomat_sql">true</prop>
                <!-- hibernate.hbm2ddl.auto参数的作用主要用于:自动创建|更新|验证数据库表结构 
                            validate:加载hibernate时,验证创建数据库表结构;
                            create:每次加载hibernate,重新创建数据库表结构;
                            create-drop:加载hibernate时创建,退出时删除表结构;
                            update:加载hibernate自动更新数据库结构 -->
                <prop key="hibernate.hbm2ddl.auto" >update</prop>
            </props>
        </property>
        <!-- 加载Hibernte的映射文件 -->
        <property name="mappingResources">
            <list>
                <value>com/muke/employee/domain/Department.hbm.xml</value>
                <value>com/muke/employee/domain/Employee.hbm.xml</value>
            </list>
        </property>
    </bean>
    
    
    <!-- **配置Action的类  -->
    <bean id="employeeAction" class="com.muke.employee.action.EmployeeAction" scope="prototype">
        <property name="employeeService" ref="employeeService"/>
        <property name="departmentService" ref="departmentService"/>
    </bean>
    <bean id="departmentAction" class="com.muke.employee.action.DepartmentAction" scope="prototype">
        <property name="departmentService" ref="departmentService"/>
    </bean>
    
    
    <!-- **配置Service业务层的类 -->
    <bean id="employeeService" class="com.muke.employee.service.impl.EmployeeServiceImpl">
        <property name="employeeDao" ref="employeeDao"/>
    </bean>
    <bean id="departmentService" class="com.muke.employee.service.impl.DepartmentServiceImpl">
        <property name="departmentDao" ref="departmentDao"/>
    </bean>
    
    
    
    <!-- **配置 Dao的类 -->
    <bean id="employeeDao" class="com.muke.employee.dao.impl.EmployeeDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <bean id="departmentDao" class="com.muke.employee.dao.impl.DepartmentDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    
    
    
    
    
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 开启注解事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" />

</beans>

applicationContext.xml

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,734评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,931评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,133评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,532评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,585评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,462评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,262评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,153评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,587评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,792评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,919评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,635评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,237评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,855评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,983评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,048评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,864评论 2 354

推荐阅读更多精彩内容

  • 本文包括:1、Filter简介2、Filter是如何实现拦截的?3、Filter开发入门4、Filter的生命周期...
    廖少少阅读 7,272评论 3 56
  • 一. Java基础部分.................................................
    wy_sure阅读 3,811评论 0 11
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,631评论 18 399
  • 蝶沾花叶,鱼戏清溪,江南处处春声。 阡陌如茵,漫听茶女歌声。 湖心一苇归去,棹东风,双桨波声。 云岫远,时鸣山寺里...
    知鱼清欢阅读 441评论 2 15
  • 这次选了个简单的。用SAI描的,抖动修正7.
    鲁狂歌阅读 259评论 0 0