创建项目 引入Sping Mvc

1.创建Maven web项目

2.引用Spring MNC 坐标

org. springframework spring-webmvc 3.2.8. RELEASE

3.配置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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值