SSM -1

使用SSMSpringSpringMVCMybatis)已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方。之前没有记录SSM整合的过程,这次刚刚好基于自己的一个小项目重新搭建了一次,而且比项目搭建的要更好一些。以前解决问题的过程和方法并没有及时记录,以后在自己的小项目中遇到我再整理分享一下。这次先说说三大框架整合过程。个人认为使用框架并不是很难,关键要理解其思想,这对于我们提高编程水平很有帮助。不过,如果用都不会,谈思想就变成纸上谈兵了!!!先技术,再思想。实践出真知。(可通过图片水印查看博客地址)

1、基本概念

1.1、Spring

        Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Development and Design中阐述的部分理念和原型衍生而来。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。 简单来说,Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架。

1.2、SpringMVC

        Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring MVC 分离了控制器、模型对象、分派器以及处理程序对象的角色,这种分离让它们更容易进行定制。

1.3、MyBatis

       MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis MyBatis是一个基于Java持久层框架。iBATIS提供的持久层框架包括SQL MapsData Access ObjectsDAOMyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis 使用简单的 XML或注解用于配置和原始映射,将接口和 Java POJOsPlain Old Java Objects,普通的 Java对象)映射成数据库中的记录。

2、开发环境搭建

如果需要,参看之前的博文:http://blog.csdn.net/zhshulin/article/details/30779873

3、Maven Web项目创建

如果需要,参看之前的博文:http://blog.csdn.net/zhshulin/article/details/37921705

4、SSM整合    

        下面主要介绍三大框架的整合,至于环境的搭建以及项目的创建,参看上面的博文。这次整合我分了2个配置文件,分别是spring-mybatis.xml,包含springmybatis的配置文件,还有个是spring-mvc的配置文件,此外有2个资源文件jdbc.propertislog4j.properties。完整目录结构如下:

使用框架都是较新的版本

       Spring 4.0.2 RELEASE

       Spring MVC 4.0.2 RELEASE

       MyBatis 3.2.6

4.1、Maven引入需要的JAR包

 为了方便后面说的时候不需要引入JAR包,我这里直接给出所有需要的JAR包,这都是基本的JAR包,每个包的是干什么的都有注释,就不再多说了。

pom.xml

<properties>
		<!-- <span id="0_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="0_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=spring&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="0" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">spring</span></a></span>版本号 -->
		<spring.version>4.0.2.RELEASE</spring.version>
		<!-- mybatis版本号 -->
		<mybatis.version>3.2.6</mybatis.version>
		<!-- log4j日志文件管理包版本 -->
		<slf4j.version>1.7.7</slf4j.version>
		<log4j.version>1.2.17</log4j.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<!-- 表示开发的时候引入,发布的时候不会加载此包 -->
			<scope>test</scope>
		</dependency>
		<!-- <span id="1_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="1_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=spring&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="1" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">spring</span></a></span>核心包 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</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-oxm</artifactId>
			<version>${<span id="2_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=spring&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="2" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">spring</span></a></span>.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</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><span id="3_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="3_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=spring&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=1&seller_id=1&di=128" target="_blank" mpid="3" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">spring</span></a></span>-webmvc</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
		</dependency>
		<!-- mybatis核心包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>${mybatis.version}</version>
		</dependency>
		<!-- mybatis/spring包 -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>1.2.2</version>
		</dependency>
		<!-- 导入<span id="4_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="4_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=java&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=2&seller_id=1&di=128" target="_blank" mpid="4" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">java</span></a></span> ee jar 包 -->
		<dependency>
			<groupId>javax</groupId>
			<artifactId>javaee-api</artifactId>
			<version>7.0</version>
		</dependency>
		<!-- 导入Mysql数据库链接jar包 -->
		<dependency>
			<groupId><span id="5_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="5_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=mysql&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=4&seller_id=1&di=128" target="_blank" mpid="5" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">mysql</span></a></span></groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.30</version>
		</dependency>
		<!-- 导入dbcp的jar包,用来在applicationContext.xml中配置<span id="6_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="6_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=%CA%FD%BE%DD%BF%E2&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=3&seller_id=1&di=128" target="_blank" mpid="6" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">数据库</span></a></span> -->
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.2.2</version>
		</dependency>
		<!-- JSTL标签类 -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<!-- 日志文件管理包 -->
		<!-- log start -->
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>${log4j.version}</version>
		</dependency>
		<!-- 格式化对象,方便输出日志 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.1.41</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>${slf4j.version}</version>
		</dependency>
		<!-- log end -->
		<!-- 映入JSON -->
		<dependency>
			<groupId>org.codehaus.jackson</groupId>
			<artifactId>jackson-mapper-asl</artifactId>
			<version>1.9.13</version>
		</dependency>
		<!-- 上传<span id="7_nwp" style="list-style: none; width: auto; height: auto; float: none;"><a target=_blank id="7_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?rs=1&u=http%3A%2F%2Fwww%2E350351%2Ecom%2Fbianchengyuyan%2FSpring%2F318424%5F3%2Ehtml&p=baidu&c=news&n=10&t=tpclicked3_hc&q=83045059_cpr&k=%D7%E9%BC%FE&k0=spring&kdi0=8&k1=java&kdi1=8&k2=%CA%FD%BE%DD%BF%E2&kdi2=8&k3=mysql&kdi3=8&k4=%D7%E9%BC%FE&kdi4=8&sid=4b77c78e5c7912b&ch=0&tu=u1807396&jk=3b5b5cc91b1d551b&cf=29&fv=15&stid=9&urlid=0&luki=5&seller_id=1&di=128" target="_blank" mpid="7" style="list-style: none; padding: 0px 10px; margin: 0px; color: rgb(0, 182, 137); text-decoration: none;"><span style="list-style: none; color: rgb(0, 0, 255); width: auto; height: auto;">组件</span></a></span>包 -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3.1</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>commons-codec</groupId>
			<artifactId>commons-codec</artifactId>
			<version>1.9</version>
		</dependency>
	</dependencies>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值