OA專案筆記
阿新 • • 發佈:2018-11-19
一、建立專案構架
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.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jcl</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> </dependencies>
1.3在pom中註冊資源目錄
<resources> <!--註冊資源目錄--> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</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&useUnicode=true&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.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<!--註冊Dao-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.edu.aynu.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!--註冊Service-->
<context:component-scan base-package="cn.edu.aynu.service"/>
<!--註冊處理器-->
<context:component-scan base-package="cn.edu.aynu.controller"/>
<!--註冊事務管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--註冊事務註解驅動-->
<tx:annotation-driven transaction-manager="transactionManager"/>
1.7修改web.xml版本
<!--註冊字元編碼過濾器-->
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.springframework.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.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</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 DATABASE IF EXISTS oa;
CREATE DATABASE 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,
`title` 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,
`title` 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.xml中新增歡迎頁面
<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;
}