spring mvc 传值问题

wowudi111 2011-11-02 02:23:48
spring mvc中的一个controller中的一个方法,在User和Custom类中都有username属性,那么我怎么能在提交的请求中来指定只给user的username传值?

public void sayTo4(@ModelAttribute("user") User user,@ModelAttribute("custom") Custom custom)
{
System.out.println("username: " + user.getUsername() + " custom.username: " + custom.getUsername());
}

class User{
string name;
...
}

class Custom{
string name;
...
}

有上面二个类,都有name属性

Controller

void hello(@ModelAttribute("user") User user,@ModelAttribute("custom") Custom custom)
{
System.out.println("user.name: " + user.getName());
System.out.println("custom.name: " + custom.getName());
}

一个表单中提交信息
<form>
<input type="text" name="????"/>
</form>

表单中问号部分应该写什么?
如果写name,那么controller中的user和costom中的name属性都会被同时赋值。

问题该如何编写这个表单,使得传给controller,只让其中user类的name被赋值。

...全文
282 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wowudi111 2011-11-02
  • 打赏
  • 举报
回复
大家帮下忙吧

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧