0

I have a rest call that takes in arbitrary query parameters. To capture these I am using @RequestParam Map queryParams.

I want each entry in the map to be bound to different type e.g. some to date, some to doubles, some to string, etc...

How can I do this?

Any code examples would be helpful.

GM

user2279337
  • 691
  • 5
  • 13
  • 26

2 Answers2

1

Does it have to be mapped to the Map in the end? You can create an auxilary object and map all the requestemParams to it like this:

CustomObjectDTO
public class CustomObjectDTO{
    private String prop1;
    private Date   prop2;
    private int    prop3;

    //Getters and setters
    // propably also the default constructor is needed
}

And your example controller:

public @ResponseBody void doSomething(CustomObjectDTO customObjectDTO){
    // do something with the object
}
pezetem
  • 2,503
  • 2
  • 20
  • 38
0

You can like that:

@RequestMapping(value= "/xxx")
public @ResponseBody void reqParamSample(ModelMap model, 
HttpServletRequest request,
@RequestParam(value="id") int id,
@RequestParam(value="name") String name){

    // do sth
}

Request param will cast to the types based on parameter name.

Burak Keceli
  • 933
  • 1
  • 15
  • 31