我有一个Spring MVC项目,我正在尝试解析URL,例如:
http://localhost:8080/app/my-controller?param1=a¶m2=256
http://localhost:8080/app/my-controller?param1=b¶m2=256
http://localhost:8080/app/my-controller?param1=c¶m2=256
我希望控制器接受同时具有param1和param2的请求,但也限制param1的值。
我尝试了以下内容:
@RestController
@RequestMapping("/my-controller")
public class MyController {
@RequestMapping(params = { "param1=a", "param1=b", "param1=c", "param2" }, method = RequestMethod.GET)
public ResponseEntity action(@RequestParam(name = "param1", required = true) String param1, @RequestParam(name = "param2", required = true) Integer param2) {
...
}
}
但上面显示的网址不匹配。
如何使用“myParam = myValue”和“myParam”样式表达式的序列指定RequestMapping参数值?
答案 0 :(得分:1)
我认为问题是你在params列表中指定了param2
,不需要什么。尝试简单地从params列表中删除它,保留其余的代码:
params = { "param1=a", "param1=b", "param1=c"}