本人Android移动开发4年经验,因为最近一段时间想着换工作,但发现移动开发现如今的大环境不是太好,于是想着转其他开发岗位,由于自己以前学过后台开发,也曾经在公司维护过一段时间的后台代码,现如今想转回java web开发于是写了下面的文章将已经java web的项目复习一下希望能对找java开发的工作有所帮助。
为了能快速的将现阶段热门的java框架上手买了一本Spring+Mybatis企业级应用实战。我将此项目分成四个分支提交到了我的github上,
四个分支分别为:
(1)master:原项目,spring+mybatis+mysql注解方式
(2)hrm_xml:spring+mybatis+mysql xml配置方式
(3)hrm_oracle:spring+mybatis+oracle xml配置方式
(4)hrm_oracle:spring+hibernate+oracle 注解方式
github地址:https://github.com/jessear/hrm
下面我将对四个分支逐一来进行讲解
spring+mybatis+mysql注解方式:
目录结构:
sql语句:
/*
Navicat MySQL Data Transfer
Source Server : localhost_3306
Source Server Version : 50717
Source Host : localhost:3306
Source Database : hrm_db
Target Server Type : MYSQL
Target Server Version : 50717
File Encoding : 65001
Date: 2017-06-21 19:38:11
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for dept_inf
-- ----------------------------
DROP TABLE IF EXISTS `dept_inf`;
CREATE TABLE `dept_inf` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`remark` varchar(300) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of dept_inf
-- ----------------------------
INSERT INTO `dept_inf` VALUES ('1', '技术部', '技术部');
INSERT INTO `dept_inf` VALUES ('2', '运营部', '运营部');
INSERT INTO `dept_inf` VALUES ('3', '财务部', '财务部');
INSERT INTO `dept_inf` VALUES ('4', '总办公', '总办公');
INSERT INTO `dept_inf` VALUES ('5', '市场部', '市场部');
INSERT INTO `dept_inf` VALUES ('6', '教学部', '教学部');
-- ----------------------------
-- Table structure for document_inf
-- ----------------------------
DROP TABLE IF EXISTS `document_inf`;
CREATE TABLE `document_inf` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`filename` varchar(300) NOT NULL,
`remark` varchar(300) DEFAULT NULL,
`create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`user_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `document_inf_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_inf` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of document_inf
-- ----------------------------
-- ----------------------------
-- Table structure for employee_inf
-- ----------------------------
DROP TABLE IF EXISTS `employee_inf`;
CREATE TABLE `employee_inf` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`dept_id` int(11) NOT NULL,
`job_id` int(11) NOT NULL,
`name` varchar(20) NOT NULL,
`card_id` varchar(20) NOT NULL,
`address` varchar(50) DEFAULT NULL,
`post_code` varchar(50) DEFAULT NULL,
`tel` varchar(16) DEFAULT NULL,
`phone` varchar(11) NOT NULL,
`qq_num` varchar(10) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`sex` int(11) DEFAULT '1',
`party` varchar(10) DEFAULT NULL,
`birthday` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`race` varchar(100) DEFAULT NULL,
`education` varchar(10) DEFAULT NULL,
`speciality` varchar(20) DEFAULT NULL,
`hobby` varchar(100) DEFAULT NULL,
`remark` varchar(500) DEFAULT NULL,
`create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `dept_id` (`dept_id`),
KEY `job_id` (`job_id`),
CONSTRAINT `employee_inf_ibfk_1` FOREIGN KEY (`dept_id`) REFERENCES `dept_inf` (`id`),
CONSTRAINT `employee_inf_ibfk_2` FOREIGN KEY (`job_id`) REFERENCES `job_inf` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of employee_inf
-- ----------------------------
INSERT INTO `employee_inf` VALUES ('1', '1', '8', '爱丽丝', '4328011988', '广州天河', '510000', '020-77777777', '13262623319', '664249862', '
[email protected]', '0', '党员', '2017-06-21 15:45:19', '满', '本科', '美声', '唱歌', '四大天王', '2017-06-21 15:45:16');
-- ----------------------------
-- Table structure for job_inf
-- ----------------------------
DROP TABLE IF EXISTS `job_inf`;
CREATE TABLE `job_inf` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) DEFAULT NULL,
`remark` varchar(300) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of job_inf
-- ----------------------------
INSERT INTO `job_inf` VALUES ('1', '职员', '职员');
INSERT INTO `job_inf` VALUES ('2', 'java开发工程师', 'java开发工程师');
INSERT INTO `job_inf` VALUES ('3', 'java中级开发工程师', 'java中级开发工程师');
INSERT INTO `job_inf` VALUES ('4', 'java高级开发工程师', 'java高级开发工程师');
INSERT INTO `job_inf` VALUES ('5', '系统管理员', '系统管理员');
INSERT INTO `job_inf` VALUES ('6', '架构师', '架构师');
INSERT INTO `job_inf` VALUES ('7', '主管', '主管');
INSERT INTO `job_inf` VALUES ('8', '经理', '经理');
INSERT INTO `job_inf` VALUES ('9', '总经理', '总经理');
-- ----------------------------
-- Table structure for notice_inf
-- ----------------------------
DROP TABLE IF EXISTS `notice_inf`;
CREATE TABLE `notice_inf` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`content` text NOT NULL,
`create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`user_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `notice_inf_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user_inf` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of notice_inf
-- ----------------------------
-- ----------------------------
-- Table structure for user_inf
-- ----------------------------
DROP TABLE IF EXISTS `user_inf`;
CREATE TABLE `user_inf` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`loginname` varchar(20) NOT NULL,
`password` varchar(16) NOT NULL,
`status` int(11) NOT NULL DEFAULT '1',
`create_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
`username` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of user_inf
-- ----------------------------
INSERT INTO `user_inf` VALUES ('1', 'admin', '123456', '2', '2017-06-21 15:55:22', '超级管理员');
lib jar包:
web.xml配置:
xmlns=" http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation=" http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
/WEB-INF/applicationContext*.xml
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/springmvc-config.xml
1
springmvc
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
characterEncodingFilter
/*
*.jsp
false
true
/WEB-INF/jsp/taglib.jsp
404
/404.html
index.jsp
applicationContext.xml配置:
xmlns:mybatis=" http://mybatis.org/schema/mybatis-spring"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:p=" http://www.springframework.org/schema/p"
xmlns:context=" http://www.springframework.org/schema/context"
xmlns:mvc=" http://www.springframework.org/schema/mvc"
xmlns:tx=" http://www.springframework.org/schema/tx"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://mybatis.org/schema/mybatis-spring
http://mybatis.org/schema/mybatis-spring.xsd ">
p:dataSource-ref="dataSource"/>
p:sqlSessionFactoryBeanName="sqlSessionFactory"/>
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource"/>
springmvc-config.xml配置:
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc=" http://www.springframework.org/schema/mvc"
xmlns:context=" http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
/WEB-INF/jsp/
.jsp
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
10485760
UTF-8