Vaadin 和 Spring MVC 集成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1185353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:54:44  来源:igfitidea点击:

Vaadin and Spring MVC Integration

springspring-mvcvaadin

提问by dakull

I'm thinking about the possibility of using Spring MVC with Vaadin Framework. Are there any documented ways of making them play nicely together ? Also is it a good idea to use them together ? relating to performance; I'm going to run the app on a dedicated server.

我正在考虑在 Vaadin 框架中使用 Spring MVC 的可能性。是否有任何记录的方法可以让它们很好地一起玩?一起使用它们也是一个好主意吗?与表现有关;我将在专用服务器上运行该应用程序。

To make my question a bit more clear, how can i return a modelandview from a Spring MVC Controller that wll render using Vaadin and can access all the model data.

为了让我的问题更清楚一点,我如何从 Spring MVC 控制器返回一个模型和视图,该控制器将使用 Vaadin 呈现并可以访问所有模型数据。

采纳答案by Jens Jansson

Spring support for Vaadin is quite new, but there has recently been a lot of talk about it on the forum and some have tested it. Seems to work. There is an article on the Vaadin wiki about it, and some threads on the forum talking about Vaadin + Spring integration:

对 Vaadin 的 Spring 支持是相当新的,但最近在论坛上有很多关于它的讨论,有些人已经对其进行了测试。似乎工作。Vaadin wiki 上有一篇关于它的文章,论坛上有一些讨论 Vaadin + Spring 集成的主题:

Wiki: Spring Integration
Forum: can it mill toolkit be integrated with spring application
Forum: Spring integration problem
Forum: Working with Spring
Forum: Spring Integration

Wiki:Spring 集成
论坛:能否将工具包与 Spring 应用程序
集成 论坛:Spring 集成问题
论坛:与 Spring 合作
论坛:Spring 集成

回答by dhrbo

Not sure if it is a prudent choice to integrate vaadin with Spring MVC. Its a waste. MVC is meant for typical page based web apps where as vaadin is more view state based like a desktop app. I would typically do a meet in the middle and have my business tier and data access layer in spring and use Vaadin as is.

不确定将 vaadin 与 Spring MVC 集成是否是一个谨慎的选择。它是一种浪费。MVC 适用于典型的基于页面的 Web 应用程序,其中 vaadin 更像桌面应用程序一样基于视图状态。我通常会在中间举行一次会议,并在春季拥有我的业务层和数据访问层,并按原样使用 Vaadin。

回答by Archie

See this threadon the Vaadin forum for my AutowiringApplicationServletsolution, including a sample WAR application.

有关我的解决方案,请参阅Vaadin 论坛上的此主题AutowiringApplicationServlet,包括示例 WAR 应用程序。

回答by gerarldlee

agreed with dhrbo.

同意dhrbo。

its not wise to use spring mvc, more so with webflow with vaadin. vaadin is another web-app framework.

使用 spring mvc 是不明智的,使用带有 vaadin 的 webflow 更是如此。vaadin 是另一个网络应用程序框架。

if you want the idea of "spring mvc" in your vaadin project, integrate it with spring-core, beans and context. that way you can get a clear separation between controllers, ui (vaadin), and models (integrate with hibernate / orms)

如果您想在 vaadin 项目中使用“spring mvc”的想法,请将其与 spring-core、bean 和上下文集成。这样你就可以在控制器、ui (vaadin) 和模型(与 hibernate / orms 集成)之间获得清晰的分离

回答by psp

Here's an article on integrating Spring service layer with Vaadin. It does not directly relate to Spring MVC that the original question was about, but it can still be a pointer for other readers researching Vaadin Spring integration.

这是一篇关于将 Spring 服务层与 Vaadin 集成的文章。它与原始问题所涉及的 Spring MVC 没有直接关系,但它仍然可以为其他研究 Vaadin Spring 集成的读者提供参考。

http://psponcoding.blogspot.com/2011/03/vaadin-spring-integration.html

http://psponcoding.blogspot.com/2011/03/vaadin-spring-integration.html

回答by Oliv

org.springframework.web.servlet.mvc.Controller's handleRequest takes a HttpServletRequestand HttpServletResponseas parameters. From these, you cannot process the URI fragment. As such, the controller is not suited for controlling requests based on URI fragment.

org.springframework.web.servlet.mvc.Controller的 handleRequest 以HttpServletRequestHttpServletResponse作为参数。从这些中,您无法处理 URI 片段。因此,控制器不适合基于 URI 片段控制请求。

In my application, I implemented very similar concept to Spring controller. My application still has a notion of "views" and "model". Each view is implemented in a separate class and is displayed in a central block of the page. I wanted to centralize logic of the URL processing to that class, so I created a class AbstractControllerEntry:

在我的应用程序中,我实现了与 Spring 控制器非常相似的概念。我的应用程序仍然有“视图”和“模型”的概念。每个视图都在一个单独的类中实现,并显示在页面的中央块中。我想将 URL 处理的逻辑集中到该类,所以我创建了一个类AbstractControllerEntry

public static abstract class AbstractControllerEntry {
    public abstract boolean matches(String fragment);
    public abstract void open(MainWindow window, String fragment);
}

with several convenience subclasses such as ConstantEntry, PrefixEntryand RegexEntry.

有几个方便的子类,例如ConstantEntry,PrefixEntryRegexEntry

Each view class has a static method, that returns AbstractControllerEntry. Collection of all entries is kept in a static array inside of MyControllerclass (not a Spring MVC controller). Upon fragment change (see UriFragmentUtility), I iterate all entries, and for first, which matches, I will call open. Any other logic, such as finding the model object, is inside of the view class, in the AbstractControllerEntryimplmentation.

每个视图类都有一个静态方法,返回AbstractControllerEntry. 所有条目的集合都保存在MyController类内部的静态数组中(不是 Spring MVC 控制器)。在片段更改时(请参阅UriFragmentUtility),我迭代所有条目,对于匹配的第一个条目,我将调用 open。任何其他逻辑,例如查找模型对象,都在视图类内部,在实现中AbstractControllerEntry

Additionaly, there's another static method to generate the URI fragment in the view class, so that each reference to a view is a real reference to a class, this is a solution to broken links. And each view has instance method to get a fragment for current view, which is checked to match a controller entry to increase robustness.

另外,在视图类中还有一个静态方法来生成URI片段,这样对视图的每个引用都是对类的真正引用,这是一个坏链接的解决方案。并且每个视图都有实例方法来获取当前视图的片段,检查该片段以匹配控制器条目以增加健壮性。