来自jsp请求参数的Spring3 ModelAttribute
是否可以抓取各种表单组件并将它们转化为相应的 DAO 对象?我试图避免为每个表单创建自定义 Bean(封装所有字段)。
例如:
<form action="/add">
<input name="foo" id="foo" value="29"/>
<input name="bar" id="bar" value="63"/>
</form>
public void add(@ModelAttribute("foo") Foo myFoo, @ModelAttribute("bar") Bar myBar)
目前,我必须使用 HttpRequest,提取值 (29,63),并将它们用作主键来查找正确的数据库对象。我不知道是否有一种快速方法可以使用 ModelAttribute 自动连接它。
谢谢!
Is it possible to grab various form components and turn them into their corresponding DAO objects? I'm trying to avoid creating a custom Bean (which encapsulates all fields) for each Form.
Ex:
<form action="/add">
<input name="foo" id="foo" value="29"/>
<input name="bar" id="bar" value="63"/>
</form>
public void add(@ModelAttribute("foo") Foo myFoo, @ModelAttribute("bar") Bar myBar)
Currently, I'd have to use the HttpRequest, extract the values (29,63), and use them as primary keys to look up the correct database objects. I didn't know if there was a quick way to auto-wire this using ModelAttribute.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用@RequestParam
You should use @RequestParam