JSP 和 Spring MVC 中的重复组件

发布于 2024-10-02 07:18:17 字数 228 浏览 0 评论 0原文

我正在使用 Spring MVC 构建一个 Web 应用程序,并且在许多不同的页面上我想包含类似“智能”组件的内容。例如,一个显示我的数据库中的各种对象的框。因此它需要能够以某种方式访问​​我的服务层,因为我不想每次使用此组件时都传递任何对象。

我考虑过使用标签,但我不想在控制器中创建所需的对象并每次将其传递给标签......而且我不想做一些从上下文加载所需服务的脏脚本。

有什么办法可以很好地做到这一点吗?

I am building a Webapp with Spring MVC and on many different pages i would like to include something like a "smart" component. For example a box that shows various objects from my database. So it needs to be able to access my service layer somehow, because I do not want to pass any object each time I use this component.

I thought about using a tag, but I don't want to create the needed objects in the controller and pass it to the tag everytime... Also I do not want to do some dirty scriptlets that load the needed services from the context.

Is there any way to do this nicely?

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

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

发布评论

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

评论(1

回心转意 2024-10-09 07:18:17

使用ajax怎么样?您可以使用 ajax 调用所需的控制器方法,该方法将提供所需的对象。您不需要在每个响应中发送该信息,因为 ajax 会获取它。

How about using ajax? You can invoke with ajax the needed controller method and this method will provide the needed object. You won't need to send that information in every response, because ajax will get it.

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