`

spring_mvc(二)Mapping Request

 
阅读更多
http://localhost:8080/spring_mvc_test/simple
@RequestMapping("simple")
public @ResponseBody String helloWorld() { 
    String message = "Hello, this is a simple example";
    System.out.println(message);
    return message;
}


mapping by path

http://localhost:8080/spring_mvc_test/mapping/path
@RequestMapping("/mapping/path")
public @ResponseBody String mappingByPath() {
     String message = "Mapping by path";
     return message;
}


mapping by method
<form action="http://localhost:8080/spring_mvc_test/mapping/method" method="post">
<input type="submit" value="提交"/>
</form>

@RequestMapping(value="/mapping/method", method=RequestMethod.POST)
public @ResponseBody String mappingByMethod() {
    String message = "Mapping by Method";
    return message;
}


By path,method,and presence of parameter

http://localhost:8080/spring_mvc_test//mapping/parameter?foo=111
@RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="foo")
public @ResponseBody String byParameter() {
	String message = "By path,method,and presence of parameter";
	return message;
}


Mapped by path + method + not presence of query parameter!


http://localhost:8080/spring_mvc_test//mapping/parameter?foo1=111

@RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="!foo") 
public @ResponseBody String mappedNotParams(){
	String message = "Mapped by path + method + not presence of query parameter!";
	return message;
}


Mapped by path + method + presence of header
@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="Accept=text/plain")
public @ResponseBody String byHeader() {
    String message = "Mapped by path + method + presence of header!";
    return message;
}


Mapped by path + method + not presence header!

http://localhost:8080/spring_mvc_test/notheader
@RequestMapping(value="/notheader", method=RequestMethod.GET, headers="!FooHeader")
public @ResponseBody String byHeaderNegation() {
    String message = "Mapped by path + method + not presence header!";
    return message;
}


Mapping by regexp!

http://localhost:8080/spring_mvc_test/regexp/ddd
http://localhost:8080/spring_mvc_test/regexp/test
@RequestMapping(value="/regexp/*", method=RequestMethod.GET)
public @ResponseBody String regexp() {
    String message = "Mapping by regexp!";
    return message;
}
分享到:
评论

相关推荐

    spring_MVC源码

    弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件。本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mvc和rest小例子没有介绍到数据层的内容,...

    Spring MVC 入门实例

    首先, 我需要在你心里建立起 Spring MVC 的基本概念. 基于 Spring 的 Web 应用程序接收到 http://localhost:8080/hello.do(事实上请求路径是 /hello.do) 的请求后, Spring 将这个请求交给一个名为 helloController ...

    springmvc demo

    Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求-响应模型,框架的目的就是帮助我们简化开发...

    spring mvc 3.2 参考文档

    Spring Web model-view-controller (MVC)框架是围绕 DispatcherServlet 设计的,并分发请求到处理程序(handler),Spring MVC支持可配置的处理程序映射(handler mapping),视图解析(view resolution)、 区域设置...

    Spring mvc中 RequestMapping 6个基本用法小结

    Spring mvc中@RequestMapping 6个基本用法小结

    Spring-Reference_zh_CN(Spring中文参考手册)

    2.5.1. Spring MVC的表单标签库 2.5.2. Spring MVC合理的默认值 2.5.3. Portlet 框架 2.6. 其他特性 2.6.1. 动态语言支持 2.6.2. JMX 2.6 .3. 任务规划 2.6.4. 对Java 5(Tiger)的支持 2.7. 移植到Spring 2.0 ...

    Manning.Spring.in.Action.4th.Edition.2014.11.epub

    7.1. Alternate Spring MVC configuration 7.1.1. Customizing DispatcherServlet configuration 7.1.2. Adding additional servlets and filters 7.1.3. Declaring DispatcherServlet in web.xml 7.2. Processing ...

    SPRING入门

    Spring MVC属于springFrameWork(spring)的产品,它是基于java的轻量级web框架,使用MVC架构模式,将web层进行解耦功能,前端控制器是DispatcherServlet;应用控制器其实拆为处理器映射器(Handler Mapping)进行处理器...

    SpringMvc源码

    Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求-响应模型,框架的目的就是帮助我们简化开发...

    跟我学SpringMVC

    Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架 构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求-响应模型,框架的目的就是帮助我们简化开 ...

    spring security 参考手册中文版

    5.1.3使用Spring MVC的AbstractSecurityWebApplicationInitializer 32 5.2 HttpSecurity 32 5.3 Java配置和表单登录 34 5.4授权请求 35 5.5处理注销 36 5.5.1 LogoutHandler 37 5.5.2 LogoutSuccessHandler 37 5.5.3...

    详解获取Spring MVC中所有RequestMapping以及对应方法和参数

    本篇文章主要介绍了详解获取Spring MVC中所有RequestMapping以及对应方法和参数,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

    spring-boot-reference.pdf

    Mapping Error Pages outside of Spring MVC 27.1.12. Spring HATEOAS 27.1.13. CORS Support 27.2. The “Spring WebFlux Framework” 27.2.1. Spring WebFlux Auto-configuration 27.2.2. ...

    轻量级java web MVC框架

    一个非常简单的MVC框架,实现了类似Spring MVC的基本功能。 1、包括自动扫描绑定映射路径,只要在web.xml中指定扫描包,系统启动后会将请求url绑定到指定的处理方法上。如: 在web.xml中定义如下: &lt;param-name&gt;...

    springmybatis

    mybatis实战教程mybatis in action之六与Spring MVC 的集成 mybatis实战教程mybatis in action之七实现mybatis分页源码下载 mybatis实战教程mybatis in action之八mybatis 动态sql语句 mybatis实战教程mybatis in ...

    spring-framework-reference-4.1.2

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    java微信公众号MVC开发框架

    jwx是开源的java公众号开发MVC框架,基于spring配置文件和微信消息或事件注解,通过微信上下文处理一个或多个微信公众号服务请求。目的主要有两个,其一生封装微信请求xml消息为java实体对象,将返回对象转换为xml...

    Usermanagement2:SpringMVC

    Spring MVC 展示 通过小而简单的用户管理示例演示 Spring MVC Web 框架的功能。 在此展示中,您将看到以下内容: The simplest possible @Controller Mapping Requests Obtaining Request Data Generating ...

    spring-framework-reference4.1.4

    3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .........................................................

    从J2SE到J2EE知识点介绍

    7. &lt;hibernate-mapping&gt;元素介绍 212 8. 元素介绍 212 9. 元素介绍 213 10. 元素介绍 214 (七) ID的生成策略 215 1. increment 216 2. identity 216 3. sequence 216 4. hilo 217 5. seqhilo 217 6. uuid 217 7. ...

Global site tag (gtag.js) - Google Analytics