一、创建项目构架

1、创建一个Maven的web工程

1.1修改编译器版本

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>10</maven.compiler.source>
        <maven.compiler.target>10</maven.compiler.target>
        <spring.version>5.0.2.RELEASE</spring.version>
    </properties>

1.2导入依赖

依赖可以直接从Maven中央仓库下载

    <dependencies>
        <!-- javax.servlet-api依赖 -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- javax.servlet.jsp-api依赖 -->
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.12</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring- </artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-jcl</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.spring work</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>

1.3在pom中注册资源目录

        <resources>
            <!--注册资源目录-->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*. </include>
                </includes>
            </resource>
        </resources>

1.4完善maven的目录结构

  • 添加src/main/java目录
  • 添加src/main/resources目录
  • 将这些目录添加上相应的功能属性

1.5定义mybatis主配置文件

    <!--为实体类指定别名-->
    <typeAliases>
        <package name=\"cn.edu.aynu.bean\"/>
    </typeAliases>

    <!--注册映射文件-->
    <mappers>
        <package name=\"cn.edu.aynu.dao\"/>
    </mappers>

1.6定义Spring配置文件

<!--注册数据源-->
    <bean id=\"dataSource\" class=\"com.alibaba.druid.pool.DruidDataSource\">
        <property name=\"url\" value=\"jdbc:mysql:///test?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8\"/>
        <property name=\"username\" value=\"root\"/>
        <property name=\"password\" value=\"12345678\"/>
    </bean>

    <!--注册SqlSessionFactory-->
    <bean id=\"sqlSessionFactory\" class=\"org.mybatis.spring.SqlSessionFactoryBean\">
        <property name=\"configLocation\" value=\"classpath:mybatis. \"/>
        <property name=\"dataSource\" ref=\"dataSource\"/>
    </bean>

    <!--注册Dao-->
    <bean class=\"org.mybatis.spring.mapper.MapperScannerConfigurer\">
        <property name=\" Package\" value=\"cn.edu.aynu.dao\"/>
        <property name=\"sqlSessionFactoryBeanName\" value=\"sqlSessionFactory\"/>
    </bean>

    <!--注册Service-->
    <context:component-scan  -package=\"cn.edu.aynu.service\"/>

    <!--注册处理器-->
    <context:component-scan  -package=\"cn.edu.aynu.controller\"/>

    <!--注册事务管理器-->
    <bean id=\"transactionManager\" class=\"org.spring work.jdbc.datasource.DataSourceTransactionManager\">
        <property name=\"dataSource\" ref=\"dataSource\"/>
    </bean>

    <!--注册事务注解驱动-->
    <tx:annotation-driven transaction-manager=\"transactionManager\"/>

1.7修改web. 版本

 <!--注册字符编码过滤器-->
    <filter>
        <filter-name>characterEncoding</filter-name>
        <filter-class>org.spring work.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!--注册中央调度器-->
    <servlet>
        <servlet-name>springmvc</servlet-name>
        <servlet-class>org.spring work.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext. </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

1.8修改webapp目录中的资源

  • 将系统原型复制到webapp目录
  • 将Maven工程中原来自带的index.jsp文件删除

2创建数据库

DROP DATA  IF EXISTS oa;
CREATE DATA  oa ;
USE oa ;

SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `department`
-- ----------------------------
DROP TABLE IF EXISTS `department`;
CREATE TABLE `department` (
  `ID` int(11) NOT NULL,
  `depname` varchar(20) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  `email` varchar(30) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of department
-- ----------------------------

-- ----------------------------
-- Table structure for `flow_manage`
-- ----------------------------
DROP TABLE IF EXISTS `flow_manage`;
CREATE TABLE `flow_manage` (
  `ID` int(11) NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `flow_name` varchar(20) DEFAULT NULL,
  `flow_uid1` int(11) DEFAULT NULL,
  `assess1` char(1) DEFAULT NULL,
  `assess_time1` date DEFAULT NULL,
  `assess_view1` varchar(50) DEFAULT NULL,
  `flow_uid2` int(11) DEFAULT NULL,
  `assess2` char(1) DEFAULT NULL,
  `assess_view2` varchar(50) DEFAULT NULL,
  `assess_time2` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of flow_manage
-- ----------------------------

-- ----------------------------
-- Table structure for `meeting`
-- ----------------------------
DROP TABLE IF EXISTS `meeting`;
CREATE TABLE `meeting` (
  `ID` int(11) NOT NULL,
  `depid` int(11) DEFAULT NULL,
  `m_type` int(11) DEFAULT NULL,
  `m_name` varchar(20) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  `start_time` date DEFAULT NULL,
  `end_time` date DEFAULT NULL,
  `room_id` int(11) DEFAULT NULL,
  `all_uid` varchar(20) DEFAULT NULL,
  `content` varchar(100) DEFAULT NULL,
  `upload` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of meeting
-- ----------------------------

-- ----------------------------
-- Table structure for `meeting_room`
-- ----------------------------
DROP TABLE IF EXISTS `meeting_room`;
CREATE TABLE `meeting_room` (
  `ID` int(11) NOT NULL,
  `room_name` varchar(20) DEFAULT NULL,
  `room_content` varchar(100) DEFAULT NULL,
  `room_pic` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of meeting_room
-- ----------------------------

-- ----------------------------
-- Table structure for `meeting_type`
-- ----------------------------
DROP TABLE IF EXISTS `meeting_type`;
CREATE TABLE `meeting_type` (
  `ID` int(11) NOT NULL,
  `fid` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of meeting_type
-- ----------------------------

-- ----------------------------
-- Table structure for `mess_group`
-- ----------------------------
DROP TABLE IF EXISTS `mess_group`;
CREATE TABLE `mess_group` (
  `ID` int(11) NOT NULL,
  `g_name` varchar(20) DEFAULT NULL,
  `g_content` varchar(50) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of mess_group
-- ----------------------------

-- ----------------------------
-- Table structure for `message`
-- ----------------------------
DROP TABLE IF EXISTS `message`;
CREATE TABLE `message` (
  `ID` int(11) NOT NULL,
  `g_id` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  `sex` char(1) DEFAULT NULL,
  `phone` varchar(20) DEFAULT NULL,
  `MSN` varchar(20) DEFAULT NULL,
  `address` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of message
-- ----------------------------

-- ----------------------------
-- Table structure for `newlabel`
-- ----------------------------
DROP TABLE IF EXISTS `newlabel`;
CREATE TABLE `newlabel` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `label_name` varchar(20) DEFAULT NULL,
  `label_content` varchar(100) DEFAULT NULL,
  `pid` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of newlabel
-- ----------------------------
INSERT INTO `newlabel` VALUES (\'1\', \'体育新闻\', \'体育新闻体育新闻体育新闻\', null);
INSERT INTO `newlabel` VALUES (\'2\', \'娱乐新闻\', \'娱乐新闻娱乐新闻娱乐新闻\', null);
INSERT INTO `newlabel` VALUES (\'3\', \'时政新闻\', \'时政新闻时政新闻时政新闻\', null);
INSERT INTO `newlabel` VALUES (\'4\', \'国际足球\', \'国际足球国际足球\', \'1\');
INSERT INTO `newlabel` VALUES (\'5\', \'CBA\', \'中国篮球中国篮球\', \'1\');
INSERT INTO `newlabel` VALUES (\'6\', \'武林风\', \'河南武林风\', \'1\');
INSERT INTO `newlabel` VALUES (\'7\', \'网球\', \'网球网球\', \'1\');
INSERT INTO `newlabel` VALUES (\'8\', \'羽毛球\', \'羽毛球羽毛球\', \'1\');
INSERT INTO `newlabel` VALUES (\'9\', \'乒乓球\', \'乒乓球乒乓球\', \'1\');
INSERT INTO `newlabel` VALUES (\'10\', \'中超联赛\', \'中超联赛中超联赛\', \'1\');
INSERT INTO `newlabel` VALUES (\'11\', \'体坛名将\', \'体坛名将体坛名将\', \'1\');
INSERT INTO `newlabel` VALUES (\'12\', \'体坛快讯\', \'体坛快讯体坛快讯\', \'1\');
INSERT INTO `newlabel` VALUES (\'13\', \'内地影讯\', \'内地影讯内地影讯\', \'2\');
INSERT INTO `newlabel` VALUES (\'14\', \'内地影星\', \'内地影星内地影星\', \'2\');
INSERT INTO `newlabel` VALUES (\'15\', \'港台影星\', \'港台影星港台影星\', \'2\');
INSERT INTO `newlabel` VALUES (\'16\', \'欧美影讯\', \'欧美影讯欧美影讯\', \'2\');
INSERT INTO `newlabel` VALUES (\'17\', \'日韩影讯\', \'日韩影讯日韩影讯\', \'2\');
INSERT INTO `newlabel` VALUES (\'18\', \'今日历史\', \'今日历史今日历史\', \'3\');
INSERT INTO `newlabel` VALUES (\'19\', \'中央要闻\', \'中央要闻中央要闻\', \'3\');
INSERT INTO `newlabel` VALUES (\'20\', \'地方要闻\', \'地方要闻地方要闻\', \'3\');
INSERT INTO `newlabel` VALUES (\'21\', \'国际动态\', \'国际动态国际动态\', \'3\');

-- ----------------------------
-- Table structure for `newmanage`
-- ----------------------------
DROP TABLE IF EXISTS `newmanage`;
CREATE TABLE `newmanage` (
  `ID` int(11) NOT NULL,
  `uid` int(11) DEFAULT NULL,
  `labelid` int(11) DEFAULT NULL,
  ` ` varchar(20) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  `time` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of newmanage
-- ----------------------------

-- ----------------------------
-- Table structure for `user_duty`
-- ----------------------------
DROP TABLE IF EXISTS `user_duty`;
CREATE TABLE `user_duty` (
  `ID` int(11) NOT NULL,
  `tid` int(11) DEFAULT NULL,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user_duty
-- ----------------------------

-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `ID` int(11) NOT NULL,
  `username` varchar(10) DEFAULT NULL,
  `password` varchar(10) DEFAULT NULL,
  `nickname` varchar(10) DEFAULT NULL,
  `worktime` date DEFAULT NULL,
  `sex` char(2) DEFAULT NULL,
  `depid` int(11) DEFAULT NULL,
  `duty` char(2) DEFAULT NULL,
  `email` varchar(20) DEFAULT NULL,
  `mobile` varchar(20) DEFAULT NULL,
  `homephone` varchar(20) DEFAULT NULL,
  `workphone` varchar(20) DEFAULT NULL,
  `fax` varchar(20) DEFAULT NULL,
  `MSN` varchar(20) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `httpaddress` varchar(30) DEFAULT NULL,
  `address` varchar(100) DEFAULT NULL,
  `content` varchar(200) DEFAULT NULL,
  `logontime` date DEFAULT NULL,
  `lastlogontime` date DEFAULT NULL,
  `logoncount` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of users
-- ----------------------------

-- ----------------------------
-- Table structure for `work_help`
-- ----------------------------
DROP TABLE IF EXISTS `work_help`;
CREATE TABLE `work_help` (
  `ID` int(11) NOT NULL,
  `file` varchar(20) DEFAULT NULL,
  `content` varchar(50) DEFAULT NULL,
  `uid` int(11) DEFAULT NULL,
  `time` date DEFAULT NULL,
  `count` int(11) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of work_help
-- ----------------------------

-- ----------------------------
-- Table structure for `workmanage`
-- ----------------------------
DROP TABLE IF EXISTS `workmanage`;
CREATE TABLE `workmanage` (
  `ID` int(11) NOT NULL,
  ` ` varchar(20) DEFAULT NULL,
  `content` varchar(300) DEFAULT NULL,
  `time` date DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of workmanage
-- ----------------------------

二、处理页面跳转

在web. 中添加欢迎页面

    <welcome-file-list>
        <welcome-file>/html/login.jsp</welcome-file>
    </welcome-file-list>

修改login.htm

  • htm扩展名修改为jsp
  • 在文件头部添加page指令

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

  • 修改login.jsp文件第31-35行代码为如下内容
    if(name==\"admin\" && pwd==\"admin\")
    {   
        location.href=\"../html/index.htm\";
        return true;
    }

 

收藏 打印