Google App Engine Java 世界中的 MVC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/862003/
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
MVC in a Google App Engine Java world
提问by thatismatt
I'm coming to Java from C# & ASP.NET MVC, I'd love to find an equivalent in the Java world that I could use on the Google App Engine. I've already started to have a play with FreeMarkerand even made the first steps towards writing a very simple framework. Ideally I wouldn't have to do all the hard work though, someone must have done this already! So my question is - what frameworks are there out there that would be familiar for me coming from ASP.NET MVC and I could use them on Google App Engine for Java.
我从 C# 和 ASP.NET MVC 来到 Java,我很想在 Java 世界中找到一个可以在 Google App Engine 上使用的等价物。我已经开始尝试使用FreeMarker,甚至迈出了编写一个非常简单的框架的第一步。理想情况下,我不必做所有艰苦的工作,但肯定有人已经这样做了!所以我的问题是 - 有哪些框架对我来自 ASP.NET MVC 来说会很熟悉,我可以在 Google App Engine for Java 上使用它们。
The key things I'd want are:
我想要的关键是:
- Simple Routing-
/products/view/1gets mapped to the view action of the products controller with the productid of 1 - Template Engine- some way of easily passing 'ViewData' to the view, and from the view easily accessing it, ideally I'd love to avoid anything that is too XMLy (thus why I like FreeMarker).
- 简单路由-
/products/view/1映射到产品控制器的视图操作,productid 为 1 - 模板引擎- 轻松将“ViewData”传递给视图的某种方式,并从视图轻松访问它,理想情况下,我希望避免任何过于 XMLy 的东西(因此我喜欢FreeMarker)。
采纳答案by pjesi
I am currently working on a Google App Engine app using Spring MVC. It is a lot more mature than ASP.NET MVC so you shouldn't be disappointed. As an added bonus you have the whole IoC power of Spring.
我目前正在使用 Spring MVC 开发 Google App Engine 应用程序。它比 ASP.NET MVC 成熟得多,所以您不应该失望。作为额外的奖励,您拥有 Spring 的全部 IoC 功能。
For the view layer I am trying out Velocity. It is pretty simple but I have yet to decide if I will prefer it over JSPs. I had a brief look at FreeMaker but didn't like what I saw. If you want to stay away from XML'y JSP templates than I recommend you give Velocity a spin.
对于视图层,我正在尝试 Velocity。它非常简单,但我还没有决定是否比 JSP 更喜欢它。我简要地看了一下 FreeMaker,但不喜欢我所看到的。如果您想远离 XML'y JSP 模板,我建议您尝试一下 Velocity。
The only problem I have had with Spring on GAE is file uploading. The MultipartResolver implementations both rely on a temporary file directory. After writing my own implementation I'm back to seamless uploading of files in my models.
我在 GAE 上使用 Spring 遇到的唯一问题是文件上传。MultipartResolver 实现都依赖于临时文件目录。在编写了我自己的实现之后,我又回到了在我的模型中无缝上传文件。
回答by Vladimir
There are a couple of MVC frameworks that you should consider (that's what I'm doing now). Initially, I went with Spring MVC (3.0) and the cold start on GAE is horrendous! It takes about 10 seconds to start (and I'm not even using anything complex, like spring security, etc), so I need to use a cron job to keep it alive. So I don't recommend that you use Spring at all on GAE.
您应该考虑几个 MVC 框架(这就是我现在正在做的)。最初,我使用 Spring MVC (3.0) 并且 GAE 的冷启动是可怕的!启动大约需要 10 秒(我什至没有使用任何复杂的东西,比如 spring 安全等),所以我需要使用 cron 作业来保持它的活动。所以我不建议你在 GAE 上使用 Spring。
Take a look at the following frameworks:
看看以下框架:
As for the templating, I use Sitemesh-- used it for quite a while now, so don't see a need to switch.
至于模板,我用的是Sitemesh——用了一段时间了,所以觉得没必要换。
Hope this helps!
希望这可以帮助!
回答by Tim
Play Framework would fit the bill. It's a modern MVC framework for Java and has a Google App Engine module to provide compatibility. See http://www.playframework.org/modules/gae.
Play Framework 符合要求。它是一个用于 Java 的现代 MVC 框架,并有一个 Google App Engine 模块来提供兼容性。请参阅http://www.playframework.org/modules/gae。
Another benefit to using Play would be portability. You can deploy Play using its built-in webserver (optionally behind apache for caching, load-balancing, etc) or you can bundle as a .war file for deployment to the many Java application servers (Glassfish, Tomcat, ...).
使用 Play 的另一个好处是便携性。您可以使用其内置的网络服务器(可选地在 apache 后面用于缓存、负载平衡等)部署 Play,或者您可以将其捆绑为 .war 文件以部署到许多 Java 应用程序服务器(Glassfish、Tomcat 等)。
回答by bluecarbon
I also have a strong preference for Freemarker. I suggest that you look at the Induction framework, its template engine is pluggable but the default support is for Freemarker. Induction is a light-weight and fast MVC framework (7.7K lines) but has many features absent in the major MVC frameworks, such as:
我也非常喜欢 Freemarker。我建议你看看 Induction 框架,它的模板引擎是可插拔的,但默认支持的是 Freemarker。Induction 是一个轻量级和快速的 MVC 框架(7.7K 行),但具有许多主要 MVC 框架所没有的特性,例如:
- dynamic reloading during development when you change the controllers, views or models
- file uploads so simple (not much different that a string input)
- no configuration required for controllers
- capability to analyze dependencies between your Models, Views and Controllers using your IDE
- regular expression based URL mappings
- best support for managing redirects of any MVC framework
- 当您更改控制器、视图或模型时,在开发期间动态重新加载
- 文件上传如此简单(与字符串输入没有太大区别)
- 控制器无需配置
- 使用 IDE 分析模型、视图和控制器之间的依赖关系的能力
- 基于正则表达式的 URL 映射
- 对管理任何 MVC 框架重定向的最佳支持
As for the file upload issue raised by @pjesi, Induction allows you to set the size threshold at which files getting written to disk. If this is set large enough it should not try to write any files to disk.
至于@pjesi 提出的文件上传问题,Induction 允许您设置文件写入磁盘的大小阈值。如果设置得足够大,则不应尝试将任何文件写入磁盘。
Check out the getting started tutorial here: http://www.inductionframework.org/getting-started-tutorial.html
在此处查看入门教程:http: //www.inductionframework.org/getting-started-tutorial.html
回答by Nicholas Hirras
JavaServer Faces (JSF) I've heard is similar to the microsoft MVC framework. (I use JSF but have never used .NET MVC). And I believe JSF 1.1 works fine on Google App Engine, and I suspect that the newer versions of JSF will work if you stick to using XHTML instead of JSPs as the templates. There are also some nice libraries which let you leverage an AJAX interface on the JSF framework, RichFaces is a popular one. Check out JavaServer Faces on sun.comand also JBoss RichFaces
我听说 JavaServer Faces (JSF) 类似于 microsoft MVC 框架。(我使用 JSF,但从未使用过 .NET MVC)。而且我相信 JSF 1.1 在 Google App Engine 上运行良好,我怀疑如果您坚持使用 XHTML 而不是 JSP 作为模板,新版本的 JSF 也能正常工作。还有一些不错的库可以让您利用 JSF 框架上的 AJAX 接口,RichFaces 是一种流行的库。查看 sun.com 上的 JavaServer Faces和 JBoss RichFaces

