2

有没有方便的方法来转动这样的东西..

@RequestMapping("/some/action/{q}/...")
public void doSomething(@PathVariable("q"), oh, my, god, a, billion, annotated parameters) { .. }

变成这样。。

@RequestMapping("/some/action/{q}/...")
public void doSomething(NiceEncapsulatingRequetObject request) { .. }

使用 Spring MVC?

4

3 回答 3

0

After checking the docs, it doesn't seem like it is supported out of the box. You could try to create your own HandlerMethodArgumentResolver which gives you this feature. You might run into some issues since you'll need a circular reference between your implementation and the HandlerMethodArgumentResolverComposite instance. Nevertheless I think it should be possible.

于 2013-01-14T08:57:33.017 回答
0

是的,spring 开箱即用地支持这一点,它通常被称为 bean 绑定。基本上你创建一个具有相同名称参数的对象,所以如果你有一个参数“q”,你的对象应该包含一个私有字符串 q,同时存在 getter 和 setter。最好不要使用任何构造函数。

Spring 只会填写它在您的对象中的参数并通过方法的参数传递它。

于 2013-01-14T09:40:43.937 回答
0

您可以创建自己的对象NiceEncapsulatingRequetObject,它的属性应该是String oh, Integer my等。如果您使用确切的名称发送请求,它将起作用

于 2013-01-16T11:58:13.973 回答