1.项目包结构如下:
2. spring配置文件springMVC.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
|
3. spring配置文件beans.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
classpath:com/sxt/domain/
org.hibernate.dialect.MySQLInnoDBDialect
true
update
|
4. web.xml文件不变
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
contextConfigLocation
classpath:beans.xml
org.springframework.web.context.ContextLoaderListener
action
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springMVC.xml
action
/
index.jsp
5. 类的代码不变。
6. 运行,测试。跟上一个项目保持一致。
Spring MVC 3.0 深入
核心原理
1. 用户发送请求给服务器。url:user.do
2. 服务器收到请求。发现DispatchServlet可以处理。于是调用DispatchServlet。
3. DispatchServlet内部,通过HandleMapping检查这个url有没有对应的Controller。如果有,则调用Controller。
4. Controller开始执行。
5. Controller执行完毕后,如果返回字符串,则ViewResolver将字符串转化成相应的视图对象;如果返回ModelAndView对象,该对象本身就包含了视图对象信息。
6. DispatchServlet将执视图对象中的数据,输出给服务器。
7. 服务器将数据输出给客户端。
spring3.0中相关jar包的含义
org.springframework.aop-3.0.3.RELEASE.jar |
spring的aop面向切面编程 |
org.springframework.asm-3.0.3.RELEASE.jar |
spring独立的asm字节码生成程序 |
org.springframework.beans-3.0.3.RELE |