SM框架整合
1 使用idea创建一个maven webapp项目
到此为止项目初步建立,需要等待maven对项目结构进行组织,直到状态栏的进度条完成,且项目的目录结构如下:
2 因为是SSM,需要操作数据库,现在准备数据以及表,此处选择mysql数据库
2.1 准备表
-- auto-generated definition create table student ( ID int auto_increment primary key, stuName varchar(32) null, stuAge tinyint null, mobile varchar(11) null, address varchar(256) null, EntranceTime date null ) ;
2.2 准备初始化数据
INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('何靖', 8, '110', '天府三街', '2017-06-06'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('小强', 18, '69776977', '中和镇', '2017-06-06'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('小迪', 22, '1456789', '天华苑', '2017-06-01'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('情歌', 24, '6454422', '成都', '2017-05-31'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('周三', 23, '1223154', '德阳', '2017-06-01'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('红牛', 32, '120', '黄山', '2017-05-31'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('大米', 16, '180', '新希望', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('小米', 22, '180', '贝立美', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('黑米', 36, '180', '新希望', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('红米', 24, '180', '一楼', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('大豆', 25, '180', '二流', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('绿豆', 26, '180', '三楼', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('灰豆', 19, '180', '四楼', '2017-06-04'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('欧阳修', 23, '122', '五棵松', '2017-05-28'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('韩明', 12, '120', '鸟巢', '2017-05-29'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('李修', 21, '120', '长安', '2017-06-14'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('韩梅梅', 12, '2132354354', '大坪', '2017-06-01'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('东北F4', 99, '121313121', '铁岭', '2017-06-01'); INSERT INTO test.student (stuName, stuAge, mobile, address, EntranceTime) VALUES ('赵四', 32, '44111221', '东北', '2017-06-07');
3 对项目目录结构进行完善
3.1 JDK环境确认
3.2 编译环境确认
3.3 配置源码、资源、web、测试的目录
3.4 配置web容器tomcat
- 点击菜单中run-edit configurations打开运行配置的界面
先不要点OK,记住哦。
3.5 建立常见的代码包结构
4 增加必要的依赖
通过在pom.xml中增加相关依赖。
4.1 增加阿里云的maven远程库,加快依赖加载速度。
<!-- 阿里云maven资源库 --> <repositories> <repository> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories>
4.2 增加jstl与javaee的相关依赖
<!-- 添加jstl依赖 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency>
4.3 增加数据库相关依赖
<!-- 添加mysql驱动依赖 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.41</version> </dependency>
4.4 增加JUNIT相关依赖
<!-- 添加junit4依赖 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <!-- 指定范围,在测试时才会加载 --> <scope>test</scope> </dependency>
4.5 增加mybatis相关依赖
<!-- 添加mybatis依赖 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.2.8</version> </dependency><!--CGLIB&asm 用于mybaitis缓存以及spring中的一些依赖-->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
</dependency>