1

Simple problem:

@Controller
class MyController {
  @RequestMapping(...)
  void test(MyModel m) {
    ...
  }
}

class MyModel {
  MyNestedModel a;
}

class MyNestedModel {
  @RequestParam("b[]")
  List<String> b;
}

This apperantly does not work, because @RequestParam only works with method parameters.

Is there a way to define the name of the request param within the model object?


Reason:

My MyModel and MyNestedModel classes is of course much bigger and I'd like to use for example ?a.b[]=TEST.


Thanks for your help :)


EDIT: Looks like this is exactly my problem: How to customize parameter names when binding spring mvc command objects

Community
  • 1
  • 1
Benjamin M
  • 23,599
  • 32
  • 121
  • 201
  • possible duplicate of [How to customize parameter names when binding spring mvc command objects](http://stackoverflow.com/questions/8986593/how-to-customize-parameter-names-when-binding-spring-mvc-command-objects) – Benjamin M Sep 16 '14 at 04:13

1 Answers1

1

Spring mvc can transfer the parameter for you. But the post data should be like:

{a.b[0] : "b1", a.b[1] : "b2"}

then you can get a list in m.a.b

xierui
  • 1,047
  • 1
  • 9
  • 22
  • No `POST`, no `JSON`. I need the data as `GET` parameters: `http;//localhost/test?a.b[]=TEST` – Benjamin M Sep 16 '14 at 08:50
  • have you try http://localhost/test?a.b[0]=TEST. I think spring mvc will handler the parameter in the same way. And I know the post worked fine. – xierui Sep 16 '14 at 08:55
  • Strange, that works. Now I have `List b` and tried the following requests: `?b=x&b=y` (works: [x, y]), `?b=x,y` (works: [x, y]), `?b[]=x` (fails), `?b[0]=x` (works: [x]), `?b[1]=y` (works: [null, y]). And when using `Set b` I can only use `?b=x&b=y` and `?b=x,y`. `?b[0]=x` doesn't work with `Set`. Seems like there's no easy way to handle `?b[]=x`. – Benjamin M Sep 16 '14 at 10:18