Multiple Spring @RequestMapping annotations

Is it possible to use multiple @RequestMapping spring annotations in a method? Like:

@RequestMapping("/")
@RequestMapping("")
@RequestMapping("/welcome")
public String welcomeHandler(){
 return("welcome");
}

@RequestMapping有一个String[]值参数,所以你应该能够像这样指定多个值:

@RequestMapping(value={"", "/", "welcome"})


From my test (spring 3.0.5), @RequestMapping(value={"", "/"}) - only "/" works, "" does not. However I found out this works: @RequestMapping(value={"/", " * "}) , the " * " matches anything, so it will be the default handler in case no others.


Doesn't need to. RequestMapping annotation supports wildcards and ant-style paths. Also looks like you just want a default view, so you can put

<mvc:view-controller path="/" view-name="welcome"/>

in your config file. That will forward all requests to the Root to the welcome view.

链接地址: http://www.djcxy.com/p/92552.html

上一篇: Spring MVC预览实现

下一篇: 多个Spring @RequestMapping注释