来自jsp请求参数的Spring3 ModelAttribute

发布于 2024-12-14 19:42:44 字数 440 浏览 2 评论 0原文

是否可以抓取各种表单组件并将它们转化为相应的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-12-21 19:42:44

您应该使用@RequestParam

public void add(@RequestParam("foo") Foo myFoo, @RequestParam("bar") Bar myBar) {
}

You should use @RequestParam

public void add(@RequestParam("foo") Foo myFoo, @RequestParam("bar") Bar myBar) {
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文