1.创建Maven web项目
2.引用Spring MNC 坐标
org. springframework spring-webmvc 3.2.8. RELEASE3.配置Spring MVC主控制器
<servlet》
D1 spatcherServlet</displ ay-nane>
《servlet- nane>D1 spatcherServlet</servlet nane>
org. springf ranework. web。servlet。DispatcherServlet</servlet.cla5s>
cdescript 1on></descript ion)
contextConfigl OC at 1onc/par 25-nane》
classpath:spring- service. xml
1
</servlet》
<servlet - mapping>
<servlet - nane>DispatcherServlet
* .do
{
4。遍写Spring MVC 配置文件
<?xml version="1.0" encoding-"UTF-8"?><beans xmlns= “http://ww. springfr anework .org/schema/beans”
xmlns:xsi-“http: //ww. m3。org/2001/XML Schena- instanc e”
xmlns :context -“http://uonw. springfranevork。org/schema/context”
xmlns :jdbc= “http: //ww. springfr anework. ong/schena/jdbc”
xmIns:jee-“http: //ww. springfranework。org/schema/jee”
xmlns:tx-“http://ww. springfr anework. org/schena/tx”
xmIns:aop-’ “http://wow. springfrasework.org/schena/aop”
xmIns:mvcn’ “http://wow. springfrasework. org/schena/mvc”
xmIns:utile “http://wow. springfrasework . org/schena/ut11”
xmIns :jpa= “http: //mn. springfr amework . org/schena/dat a/Jpa”
x51 s schemal ocat Lon-"
http://ww. springfr amework .org/schema/beans http://ww. spr ingframework。org/schema/
beans/spring- beans- 3.2。xSd
http://ww. springframework。org/schena/context http://. springframework . org/schema/
context/spring-context-3.2. x5d
http://ww. springframework .org/schema/jdbc http://aaw. springframework。org/schena/jdbc/
spring-jdbc-3.2.xsd
http://ww. springframework .org/schema/jee http://ww. springfranework. org/schema/jee/
spring.fee-3+2.xsd
http://ww. springfranework。org/schema/tx http://wnw. springfranework.org/schema/tx/
spring-tx-3.2.xsd
http://ww. springfrasework . org/schena/data/jpa http://ww. springfranework. org/schena/
data/jpa/spring-jpa-1.3. xsd
http://unw. springfranework . org/schema/aop http://wu. springfranework . org/schema/ aop/
spring- aop-3.2.xsd
http://ww. springframework .org/schena/mvc http://www. springfr anework , org/schena/mvc/
spring-mvc-3.2.xsd
http://uww. springframework . org/schema/uti1 http://wow. springfr amework , org/schea/uti1/
spring-ut11-3.2.xsd">
5.编写控制器,测试Spring MVC可以使用
gController //自动的在Spring容器中创建Bean对象,Bean ID demoController
gRequestMapping("/test")//映射URL路衢/test
public class DemoController {
@RequestMapping("/hello")//映射URL路衢/hello映射的完整路径: http://
localhost:8888/Spring1/test/hello. do
@ResponseBody 1/自动处理返回值,特字符串送到浏克器
public string hello(){
return “Hello World”; ”1
6.URBL测试
http://localhost :8888/Spring1/test/he1lo.do