是否有一个好的 Java 后端平台/库/框架来保持后端和前端松散耦合?

发布于 2024-10-11 12:50:07 字数 256 浏览 2 评论 0 原文

最近的 asp.net MVC 经验大大减少了我从前端/UI 开发角度对 .NET 的厌恶。 Java 中是否有类似的东西,或者 servlet/portlet 业务(我只是模糊地理解为为了某种多任务性能优势而做 CGI 以外的事情)总是需要与 HTML 紧密耦合?

如果没有,我需要阅读什么来帮助用 Java 编写一些东西来实现这一点?一些流行的图书馆是罪魁祸首吗?

另外,如果这些神秘的 n-let 提高了性能,为什么这么多 Java 站点在我看来加载速度较慢?

Recent asp.net MVC experience has drastically reduced my .NET hate from the front-end/UI dev perspective. Is there anything similar in Java or does that servlet/portlet business which I only vaguely understand as doing something other than CGI for some sort of multitasking performance benefit always require tight-coupling to the HTML?

If not, what would I need to read up on to help write something in Java that makes this possible? Is some popular library the culprit?

Also, if these mysterious n-lets improve performance why do so many Java sites seem slower on load-time to me?

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

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

发布评论

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

评论(4

灰色世界里的红玫瑰 2024-10-18 12:50:07

Struts、Java Server Facelets、MVC、MVVM 以及目前热门的任何其他模式通常都有一个 Java 版本,具有一定程度的有用性或实用性(有些好,有些坏,就像其他所有模式一样)世界的一部分)。

阅读模式和基础计算机科学。也许你可以去阅读大量的 RFC,因为这是一条人迹罕至的道路,它会给你提供超出你最疯狂梦想的信息,让你在普通程序员看来不可思议。完成此操作后,实现诸如 MVC 模式之类的解耦系统似乎是一件简单的工作。

许多 java 站点的加载速度似乎较慢,原因有多种:1) 管理不善 2) 编码不当 3) 首次访问时的 JSP 编译时间(即阅读 JSP 的工作原理)。

无论如何,我希望这个答案有所帮助。

Struts, Java Server Facelets, more than I want to list out MVC, MVVM, and any other pattern that's hot at the moment usually has a Java version floating around somewhere with some degree of usefulness or utility (some good some bad as in every other part of the world).

Read up on Patterns and basic computer science. Maybe go the read a shit ton of RFCs route as its the road less traveled and will give you information beyond your wildest dreams and make you seem incredible to regular programmers. After doing this implementing decoupled systems such as MVC pattern will seem like simple work.

Many java sites seem slower on load time because of a variety of reasons revolving around 1) poorly administered 2) poorly coded 3) JSP compile time on first access (ie read up on how JSPs work).

Anyways, I hope this answer helps.

苏大泽ㄣ 2024-10-18 12:50:07

我不确定你所说的与前端“紧密耦合”是什么意思。

Servlet 并不总是要求它们了解调用它们的客户端。但他们必须就要来回发送的东西达成一致。将两者完全解耦的一种方法是使用商定的有线协议,无论是基于 REST 的 HTTP 或 XML,还是可怕的 SOAP。消息是交换的,但生产和消费的细节是相互隐藏的。

如果您使用 Spring(我衷心支持 Spring),您就不必被 JSP 所束缚。 Spring Web 服务和 Velocity 生成的视图是其他选择。

I'm not sure what you mean by "tight coupling" with the front end.

Servlets need not always demand that they know about the client that's calling them. But they have to agree on something to be sent back and forth. One way to completely decouple the two is to use an agreed-upon wire protocol, be it REST-based HTTP or XML or - horrors - SOAP. Messages are exchanged, but the details of production and consumption are hidden from each other.

If you use Spring, which I heartily endorse, you need not be locked into JSPs. Spring web services and Velocity generated views are other alternatives.

十年九夏 2024-10-18 12:50:07

Have a look at JSF 2.0, maybe in conjunction with Spring.

On the other hand, have a look at Spring MVC (3.0), it does not support the component style like JSF (and i think .asp) but it is a very good MVC framwork.

冷了相思 2024-10-18 12:50:07

我经常使用的框架是Spring MVC。它合理地让您将视图 (JSP) 与业务逻辑分开。

编辑:仅 JSP 是不够的。可以将所有逻辑放入单个 JSP 中 - 可以创建新的数据库连接、获取一些行、执行一些逻辑,然后显示它们。 这是一个非常糟糕的主意。通过使用 Spring MVC(或另一个 MVC 框架 - 可能还有其他框架),您可以分离业务逻辑(模型)和用户的外观(视图)以及获取数据并将所有内容连接在一起的逻辑(控制器)。

The framework I use a lot of the time is Spring MVC. It does a reasonable job of letting you keep your view (JSPs) separate from business logic.

EDIT: JSP alone is not sufficient. It is possible to put all your logic into a single JSP - it is possible to create a new database connection, fetch some rows, do some logic, and then display them. This is a very bad idea. By using Spring MVC (or another MVC framework - there are probably others out there), you separate the business logic (model), how things look to the user (view) and the logic for fetching data and wiring everything together (controller).

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