Announcement Announcement Module
No announcement yet.
@RequestParam value field for POJOs holding request parameters? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @RequestParam value field for POJOs holding request parameters?


    Please excuse a somewhat stupid question but I am having a problem with @RequestParam which I can't seem to get around.

    Im creating a service that takes 30+ request parameters. Some of these parameters are named so that I can not create fields in java to match their names. I have no control over the parameter names. With then @RequestParam annotation I can use the value field to map names to method arguments. How do I do the same for fields in a POJO?

    Example of how its done with @RequestParam

    public void doSomething(@RequestParam(value="-stupid_name1") validParamNameOne,@RequestParam(value="stupid-name2") validParamNameTwo (...))
    This becomes quite cumbersome with 30+ parameters. So I want to do:

    public void doSomething(ParamPojo paramPojo)
    and then in ParamPojo do

    class ParamPojo{
    @NiceAnnotation(value="-stupid_name1") // <- this annotation or equivalent is what i am looking for
    private String validParamNameOne;
    Is there a way this can be done or have I missed something regarding how spring handles binding of paramaters that can not match java fields?

  • #2
    But you can create a java object with fields matching named parameters. you can use String[], any other collection type (List<String>) to match your group of checkboxes, radio buttons or multiple selected dropdowns, etc. refer this: