Java 如何使用Spring MVC RequestMapping拥有多个参数?
我在这里使用springmvcJava 如何使用Spring MVC RequestMapping拥有多个参数?,java,spring,url,spring-mvc,Java,Spring,Url,Spring Mvc,我在这里使用springmvcRequestMapping来获取GET参数。以下是我的密码- @RequestMapping(value = "index", method = RequestMethod.GET) public HashMap<String, String> handleRequest(@RequestParam("dc1Servers") String dc1Servers) { HashMap<String, String> model =
RequestMapping
来获取GET
参数。以下是我的密码-
@RequestMapping(value = "index", method = RequestMethod.GET)
public HashMap<String, String> handleRequest(@RequestParam("dc1Servers") String dc1Servers) {
HashMap<String, String> model = new HashMap<String, String>();
String helloWorld = "Hello World!";
model.put("greeting", helloWorld);
System.out.println(dc1Servers);
return model;
}
所以我做了一个这样的方法,可以接受三个输入参数-
@RequestMapping(value = "index", method = RequestMethod.GET)
public HashMap<String, String> handleRequest(@RequestParam("dc1Servers") String dc1Servers, @RequestParam("dc2Servers") String dc2Servers, @RequestParam("dc3Servers") String dc3Servers) {
HashMap<String, String> model = new HashMap<String, String>();
String helloWorld = "Hello World!";
model.put("greeting", helloWorld);
System.out.println(dc1Servers);
System.out.println(dc2Servers);
System.out.println(dc3Servers);
return model;
}
这给了我一些错误。。你知道我在这里做错了什么吗?应该是这样的
http://127.0.0.1:8080/dataweb/index?dc1Servers=7&dc2Servers=7&dc3Servers=7
请更改并重试
&在每个参数之间工作
??仅在url参数的开头起作用
检查这个例子
你也能帮我吗?谢谢你的帮助。
http://127.0.0.1:8080/dataweb/index?dc1Servers=7?dc2Servers=7?dc3Servers=7
http://127.0.0.1:8080/dataweb/index?dc1Servers=7&dc2Servers=7&dc3Servers=7