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

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.