java mvc框架实例下载_SpringMVC4 Hello World源码案例下载

Spring专题

SpringMVC4 Hello World源码案例下载

Spring的web模型 - 视图 - 控制器(MVC)框架提供了一个模型 - 视图 - 控制器架构,可用于开发灵活的,松散耦合的Web应用程序。

框架是围绕DispatcherServlet 为核心处理http,处理步骤如下:

DispatcherServlet 接受一个请求

DispatcherServlet使用HandlerMapping 调用相应的控制器

控制器获得请求,基于GET or POST 方式调用相应的服务方法,.服务方法将设置我们定义的业务模型,返回视图名称给DispatcherServlet.

DispatcherServlet将从ViewResolver获得帮助,挑选出这个请求的视图

DispatcherServlet传送模型数据给视图,视图最后渲染输出给浏览器

主要步骤如下:

1.在项目目录创建Maven依赖pom.xml:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

4.0.0

com.javacodegeeks.snippets.enterprise

springexample

war

0.0.1-SNAPSHOT

springexample Maven Webapp

http://maven.apache.org

junit

junit

3.8.1

test

org.springframework

spring-core

${spring.version}

org.springframework

spring-webmvc

${spring.version}

springexample

4.0.2.RELEASE

2.创建控制器代码:

@Controller

@RequestMapping("/helloWorld")

public class HelloWorldController {

@RequestMapping(method = RequestMethod.GET)

public String hello(ModelMap model) {

model.addAttribute("name", "JCG Hello World!");

return "helloWorld";

}

}

3.创建视图:

Spring 4.0.2 MVC web service

Name : ${name}

4.配置Spring:

web.xml:

Archetype Created Web Application

mvc-dispatcher

org.springframework.web.servlet.DispatcherServlet

1

mvc-dispatcher

/

mvc-dispatcher-servlet.xml的配置:

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

/WEB-INF/

.jsp

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值