使用复杂对象将 Struts2 数据从 Jsp 传输到 Action

发布于 2024-09-04 08:33:51 字数 167 浏览 1 评论 0原文

如何使用模型驱动或对象支持的方法来映射深度超过一的复杂对象。例如,我有一个带有属性 User 对象的操作类,并且 User 有一个地址对象作为其属性。地址将街道名称作为属性。就像.. User.address.streetName

在JSP中,使用s:textfield或其他标签如何表示街道名称。 谢谢

how to use Model-driven or Object-backed approaches to map Complex Object with depth more than one. for example, I have action class with property User object and USer has a address object as its property. Address has street name as property. like .. User.address.streetName

In JSP, using s:textfield or other tags how can I represent street name.?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

千と千尋 2024-09-11 08:33:51

这有什么问题吗?

<s:property value="user.address.streetName" />

在传统设置中,这将调用 yourAction.getUser().getAddress().getStreetName()

并以其他方式,例如。当提交表单(jsp 到 Action)时,这将转换为
yourAction.getUser().getAddress().setStreetName(param)
为此,您必须确保 getUser()getAddress() 不返回 null(或者至少 Struts 可以使用空构造函数创建 - 并且设置该对象,IIRC)。

What is the problem with this?

<s:property value="user.address.streetName" />

In the traditional setting, this will call yourAction.getUser().getAddress().getStreetName()

And in the other way, eg. when submiting a form (jsp to Action), that would translate to
yourAction.getUser().getAddress().setStreetName(param)
For this to work, you just must be sure that getUser() and getAddress() do not return null (or at least that Struts can create -with empty constructor- and set that objects, IIRC).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文