ITeye博客

spring_mvc(二)Mapping Request

mistbow · 2011-12-05 18:49 · spring_mvc · 编程语言 · Markdown

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]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。