【问题标题】:Spring form data binding - how to map a form property to a form attribute (when the form-property has a different name than the form-object)Spring表单数据绑定-如何将表单属性映射到表单属性(当表单属性与表单对象的名称不同时)
【发布时间】:2010-12-10 09:31:26
【问题描述】:
public class MyForm {
  private String username;
  //getter...setter
}


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

如果我向上面的控制器提交一个带有参数“用户名”的表单,一切都会很好。 不过我很好奇,为了方便用户,我想将“用户名”参数缩短为“u”,如:http://mydomain.com?u=rocky(而不是http://mydomain.com?username=rocky)。

但我宁愿没有 MyForm.u,因为将来的可维护性有点难以阅读。

我可以将 MyForm.username 映射到表单参数“u”吗?容易吗?

【问题讨论】:

    标签: java data-binding spring-mvc


    【解决方案1】:

    我可以将 MyForm.username 映射到表单吗 参数'u'?容易吗?

    你可以(但不容易;))。

    类似问题:In Spring-mvc the attribute names in view have to always match the property names in model?(和其他用户一样,我也在这个问题下提供了答案。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多