基于Javaweb的员工/学生信息管理系统的设计与实现

购买者均提供项目技术支持,请购买后直接联系客服QQ:2580505920

 

Spring+Mybatis快速开发人员信息管理系统

相似案例

基于Javaweb的员工信息管理系统的设计与实现

基于Javaweb的学生信息管理系统的设计与实现

基于Javaweb的人员信息管理系统的设计与实现

项目介绍

案例:人员信息管理系统

主要技术:Servlet、JSP、Spring IOC、Spring AOP、Mybatis、Mybatis整合Spring、MySQL

开发环境:数据库MySQL5.7、Web容器Tomcat8.5、开发工具Intellij IDEA

项目结构

三层架构:持久层Mybatis、表现层Servlet+JSP、Spring管理对象,切面处理

基于MVC模式:视图JSP、模型JavaBean、控制器Servlet+JavaBean

效果展示

项目实现

数据库设计

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for department
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `address` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of department
-- ----------------------------
BEGIN;
INSERT INTO `department` VALUES (1, '人事部', '综合楼');
INSERT INTO `department` VALUES (2, '外交部', '北京');
COMMIT;

-- ----------------------------
-- Table structure for log
-- ----------------------------
DROP TABLE IF EXISTS `log`;
CREATE TABLE `log` (
  `opr_time` datetime NOT NULL,
  `type` varchar(10) NOT NULL,
  `operator` varchar(20) NOT NULL,
  `moudle` varchar(20) NOT NULL,
  `operation` varchar(20) NOT NULL,
  `result` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of log
-- ----------------------------
BEGIN;
INSERT INTO `log` VALUES ('2018-09-19 23:13:15', 'login', 'geek', 'SelfController', 'login', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:19', 'operation', 'geek', 'LogController', 'systemLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:20', 'operation', 'geek', 'LogController', 'loginLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:24', 'operation', 'geek', 'StaffController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:33', 'operation', 'geek', 'StaffController', 'edit', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:33', 'operation', 'geek', 'StaffController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:35', 'operation', 'geek', 'LogController', 'operationLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:45', 'operation', 'geek', 'LogController', 'loginLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:47', 'operation', 'geek', 'LogController', 'systemLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:48', 'operation', 'geek', 'LogController', 'operationLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:50', 'operation', 'geek', 'DepartmentController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:51', 'operation', 'geek', 'StaffController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:13:55', 'operation', 'geek', 'LogController', 'operationLog', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:14:02', 'operation', 'geek', 'StaffController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:14:03', 'operation', 'geek', 'DepartmentController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-19 23:14:06', 'operation', 'geek', 'LogController', 'operationLog', '成功');
INSERT INTO `log` VALUES ('2018-09-20 15:45:17', 'login', 'geek', 'SelfController', 'login', '成功');
INSERT INTO `log` VALUES ('2018-09-20 15:45:38', 'operation', 'geek', 'StaffController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-20 15:46:27', 'operation', 'geek', 'DepartmentController', 'list', '成功');
INSERT INTO `log` VALUES ('2018-09-20 15:46:42', 'operation', 'geek', 'LogController', 'operationLog', '成功');
INSERT INTO `log` VALUES ('2018-09-20 15:47:01', 'operation', 'geek', 'LogController', 'loginLog', '成功');
INSERT INTO `log` VALUES ('2018-09-20 15:47:15', 'operation', 'geek', 'LogController', 'systemLog', '成功');
COMMIT;

-- ----------------------------
-- Table structure for staff
-- ----------------------------
DROP TABLE IF EXISTS `staff`;
CREATE TABLE `staff` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  `status` varchar(10) NOT NULL,
  `did` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  `sex` varchar(2) DEFAULT NULL,
  `id_number` char(18) DEFAULT NULL,
  `work_time` datetime DEFAULT NULL,
  `leave_time` datetime DEFAULT NULL,
  `born_date` date DEFAULT NULL,
  `info` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of staff
-- ----------------------------
BEGIN;
INSERT INTO `staff` VALUES (1, 'geek', '111111', '1', 1, 'geekerstar', '男', '38424923482', '2018-09-19 22:48:46', '2018-09-19 22:48:51', '2018-09-12', NULL);
INSERT INTO `staff` VALUES (2, 'hehe', '123456', '正常', 1, '哈哈', '男', '3242343534534', '2018-09-19 22:50:15', NULL, '2010-04-02', '213231');
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;

 

项目结构

  • sm:父Module、全局定义与组织
  • sm_service:持久层、业务层
  • sm_web:表现层、Servlet依赖

Spring全局配置

<?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.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">

    <!--spring整合mybatis-->
<!--    配置数据源-->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql:///sm?useUnicode=true&amp;characterEncoding=utf-8"/>
        <property name="username" value="root"/>
        <property name="password" value="210819"/>
    </bean>

<!--    Mybatis配置-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.geekerstar.sm.entity"/>
    </bean>

<!--    自动映射-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.geekerstar.sm.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
    </bean>

    <!--声明式事务-->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="get*" read-only="true"/>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="search*" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="txPointcut" expression="execution(* com.geekerstar.sm.service.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
    </aop:config>

    <!--全局扫描-->
    <context:component-scan base-package="com.geekerstar.sm"/>
    <aop:aspectj-autoproxy/>
</beans>

 

部分代码

编码过滤器

import javax.servlet.*;
import java.io.IOException;

public class EncodingFilter implements Filter {

    private String encoding = "UTF-8";

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        if (filterConfig.getInitParameter("ENCODING")!=null)
            encoding = filterConfig.getInitParameter("ENCODING");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding(encoding);
        servletResponse.setCharacterEncoding(encoding);
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {
        encoding=null;
    }
}

 

配置文件

<!--  编码过滤器-->
  <filter>
    <filter-name>Encoding</filter-name>
    <filter-class>com.geekerstar.sm.global.EncodingFilter</filter-class>
    <init-param>
      <param-name>ENCODING</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>Encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

核心控制器

Servlet对象由Web容器管理、Service对象由IOC容器管理

 

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class DispatcherServlet extends GenericServlet {

    private ApplicationContext context;

    public void init() throws ServletException {
        super.init();
        context = new ClassPathXmlApplicationContext("spring.xml");
    }
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request =(HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;

        String path = request.getServletPath().substring(1);
        String beanName= null;
        String methodName =null;
        int index = path.indexOf('/');
        if (index!=-1){
            beanName=path.substring(0,index)+"Controller";
            methodName = path.substring(index+1,path.indexOf(".do"));
        }else{
            beanName="selfController";
            methodName = path.substring(0,path.indexOf(".do"));
        }
        Object obj = context.getBean(beanName);
        try {
            Method method = obj.getClass().getMethod(methodName,HttpServletRequest.class,HttpServletResponse.class);
            try {
                method.invoke(obj,request,response);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
<servlet>
    <servlet-name>Global</servlet-name>
    <servlet-class>com.geekerstar.sm.global.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Global</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

 

 

 

 

 

 

 

本站所有资源均由网友共享,仅用于参考学习用,请勿直接商用,如有侵权,请联系网站客服删除相关资源。若由于商用引起版权纠纷,一切责任均由使用者承担。
猿码素材 » 基于Javaweb的员工/学生信息管理系统的设计与实现

Leave a Reply

欢迎加入猿码素材,上传源码收益100%归作者所有!

立即加入 了解详情