【发布时间】:2012-05-06 22:38:45
【问题描述】:
我遇到了下一个问题。我已经在控制器中声明了一个方法,就像下一个一样,用作 Web 服务:
@RequestMapping(value = "/" + "prueba" , method = RequestMethod.GET)
public void prueba(ExampleBean pExample1, ExamlpleBean pExample2) {
// Wonderful code here
}
ExampleBean 类只是一个 Bean:
public class ExampleBean implements Serializable {
private String id;
private String whatever;
// getters, setters, and more.
}
如果界面是这样的:
@RequestMapping(value = "/" + "prueba" , method = RequestMethod.GET)
public void prueba(ExampleBean pExample1) {
// Wonderful code here
}
每次我想调用那个 web 服务时,我都会用下面的方式调用 URL:
http://myWebProject/prueba?id=1&whatever=hola
但是...当我必须为同一类的两个参数赋值时,我该怎么办?我的意思是,我不能重复参数,所以我不知道在编写 URL 时如何区分 pExample1 的 id 和 pExample2 的 id。
我的意思是,也有两个来自不同类的参数,但有一个同名的属性。例如,如果第二个参数来自 DifferentExampleBean 类,该类也有一个“id”参数。
非常感谢!
PS:我正在使用 StringHttpMessageConverter。
【问题讨论】:
-
你可以使用可变参数吗?
prueba(ExampleBean... exampleBean) -
嗯...对不起,也许我必须重新提出这个问题。我想知道当 2 个参数具有相同名称时我该怎么做。我的意思是,即使来自不同类的两个参数具有同名的一个属性。但是感谢您的兴趣;-)
标签: web-services spring spring-mvc parameter-passing spring-3