2009-01-18 88 views

回答

78

是的,你可以使用params元素:

@RequestMapping("/test.html", params = "day=monday") 
public void writeMonday() { 
} 

@RequestMapping("/test.html", params = "day=tuesday") 
public void writeTuesday() { 
} 

你甚至可以在地图基础上,存在一个特性参数的情况下

@RequestMapping("/test.html", params = "day") 
public void writeSomeDay() { 
} 

@RequestMapping("/test.html", params = "!day") 
public void writeNoDay() { 
} 
+4

这对我来说显示语法错误(在春季3),但下面的工作。 @RequestMapping(value =“/ test.html”,params =“day = monday”) – pMan 2010-08-11 10:08:22

+0

所有示例在Spring 3上都适用于我。 – Bobo 2011-03-14 19:45:12

51

或者你可以这样做:

@RequestMapping("/test.html") 
public void writeSomeDay(@RequestParam String day) { 
    // code to handle "day" comes here... 
}