---
title: "spring_mvc（二）Mapping Request"
author: "mistbow"
date: "2011-12-05T18:49:04Z"
tags: []
categories: ["编程语言"]
slug: "spring-mvc-mapping-request"
draft: false
lastmod: "2011-12-05T20:01:08Z"
id: 1292457
url: "https://mistbow.iteye.com/blog/1292457"
---

http://localhost:8080/spring\_mvc\_test/simple \[code="java"]@RequestMapping("simple") public @ResponseBody String helloWorld() { String message = "Hello, this is a simple example"; System.out.println(message); return message; }\[/code] \[color=blue]mapping by path\[/color] http://localhost:8080/spring\_mvc\_test/mapping/path \[code="java"]@RequestMapping("/mapping/path") public @ResponseBody String mappingByPath() { String message = "Mapping by path"; return message; }\[/code] \[color=blue]mapping by method\[/color] \[code="java"]

\[/code] \[code="java"]@RequestMapping(value="/mapping/method", method=RequestMethod.POST) public @ResponseBody String mappingByMethod() { String message = "Mapping by Method"; return message; }\[/code] \[color=blue]By path,method,and presence of parameter\[/color] http://localhost:8080/spring\_mvc\_test//mapping/parameter?foo=111 \[code="java"]@RequestMapping(value="/mapping/parameter", method=RequestMethod.GET, params="foo") public @ResponseBody String byParameter() { String message = "By path,method,and presence of parameter"; return message; }\[/code] \[color=blue]Mapped by path + method + not presence of query parameter! \[/color] http://localhost:8080/spring\_mvc\_test//mapping/parameter?foo1=111 \[code="java"]@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; }\[/code] \[color=blue]Mapped by path + method + presence of header\[/color] \[code="java"]@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; }\[/code] \[color=blue]Mapped by path + method + not presence header!\[/color] http://localhost:8080/spring\_mvc\_test/notheader \[code="java"]@RequestMapping(value="/notheader", method=RequestMethod.GET, headers="!FooHeader") public @ResponseBody String byHeaderNegation() { String message = "Mapped by path + method + not presence header!"; return message; }\[/code] \[color=blue]Mapping by regexp!\[/color] http://localhost:8080/spring\_mvc\_test/regexp/ddd http://localhost:8080/spring\_mvc\_test/regexp/test \[code="java"]@RequestMapping(value="/regexp/\*", method=RequestMethod.GET) public @ResponseBody String regexp() { String message = "Mapping by regexp!"; return message; }\[/code]