3
public class MyForm {
  private String username;
  //getter...setter
}


@Controller
public class MyController {
  @RequestMapping("/handleForm")
  public String handleForm( MyForm form, Model model ){
    //do something
  }
}

If I submit a form to the above controller with a parameter 'username' all works great. I am currious though, just for user convenience I'd like to shorten the 'username' parameter to 'u' as in: http://mydomain.com?u=rocky (rather than http://mydomain.com?username=rocky).

But I'd rather not have MyForm.u, it's a little hard to read for future maintainability.

Can I map MyForm.username to the form parameter 'u'? Easily?

David Parks
  • 30,789
  • 47
  • 185
  • 328

1 Answers1

1

Can I map MyForm.username to the form parameter 'u'? Easily?

You can (but not easily ;) ).

Similar question : In Spring-mvc the attribute names in view have to always match the property names in model? (Like other users, I've also provided the answer under this question.)

Community
  • 1
  • 1
dira
  • 30,304
  • 14
  • 54
  • 69