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 分离了控制器、模型对象、分派器以及处理程序对象的角色,这种分离让它们更容易进行定制。
2.环境搭建详解
2.1引入相应的包
springMVC和spring包的结构发生了很大的变化,各个包都分开了,灵活,要求使用者更加深入的学习使用,当我们引入包的时候,以少为原则,少的话可以根据报错来找到相应的包,如果过多的话,包会报错异常的混乱,不容易分辨;sprinMVC和spring本身就是一家的,所以引入的包来说基本上和spring需要的架构包是一致的.
在WEB-INF文件夹下新建注解文件springMVC-servlet.xml文件
xmlns=\ans\ xmlns:xsi=\-instance\ xmlns:aop=\chema/aop\ xmlns:context=\rg/schema/context\ xmlns:jdbc=\schema/jdbc\ xmlns:mvc=\chema/mvc\ xmlns:p=\ema/p\ xmlns:tx=\hema/tx\ xmlns:util=\schema/util\ xsi:schemaLocation=\ork.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd\> class=\ernalResourceViewResolver\ p:viewClass=\t.view.JstlView\ p:prefix=\ p:suffix=\ />
一个项目的全局配置点在web.xml,一个项目需要使用了多少框架,通过xml可以查看.
xmlns:xsi=\instance\ xmlns=\ xsi:schemaLocation=\javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\ id=\ version=\>
框架配置完成启动服务器测试框架是否搭建成功,如果服务器正常启动说明框架搭建成功,反之框架没有搭建成功 下面一个登陆小demo
Spring的实体类层(bean层)
xmlns:xsi=\instance\ xmlns=\ xsi:schemaLocation=\javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\ id=\ version=\>