当 Servlet、JSP 和轻量级 DAO 层都可以工作时,为什么还要使用 MVC 框架?

发布于 2024-08-06 11:58:06 字数 147 浏览 5 评论 0原文

我发现很难接受 Java MVC 框架,因为看起来 Servlet、JSP 和轻量级 DAO 几乎可以完成您需要它做的所有事情,以解耦控制器/视图/模型。对于 PHP,我可以看到必要性,因为没有像 servlet 这样的内置结构,但是 Java MVC 框架真的能给你带来更多吗?

I'm finding it difficult to embrace a Java MVC framework, when it looks as if Servlets, JSPs and a lightweight DAO will do just about everything you need it to do in order to decouple the controllers/views/models. For PHP I can see the necessity since there are no built in constructs like servlets, but do Java MVC frameworks really give you THAT much more?

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

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

发布评论

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

评论(2

土豪我们做朋友吧 2024-08-13 11:58:06

Servlet/JSP 的弱点之一是可测试性。尽管当然可以使用模拟来对 Servlet 进行单元测试,但它们感觉在设计时并未考虑到单元测试。 JSP 甚至更棘手。您可以依赖 Selenium 等功能测试,但现在,人们想要单元测试覆盖率。一些更现代的 Java MVC 框架为您提供了更容易测试的代码单元。

但总的来说,您认为使用 MySQL 数据库的普通旧 Tomcat 堆栈即可完成工作,这一点肯定是正确的。

One area where Servlets/JSPs are somewhat weak is testability. Although it's certainly possible to unit test Servlets using mocks, they don't feel like they were designed with unit testing in mind. JSPs are even trickier. You could rely on functional tests ala Selenium, but these days, people want unit test coverage. Some of the more modern Java MVC frameworks give you more easily testable code units.

On the whole though, you're certainly correct that a plain old Tomcat stack with a MySQL database gets the job done.

我的奇迹 2024-08-13 11:58:06

大多数 Web 框架都会抽象出底层细节。例如,WicketTapestryJavaServer Faces 允许您根据组件进行思考(例如,按钮、标签、下拉列表等)而不是 http 协议。甚至是面向操作的 Web 框架,例如 Spring MVCStruts 为您带来比所使用的底层技术更高的水平。

作为额外的好处,这些框架具有额外的功能,例如 Ajax、Comet、与持久性框架的集成,开箱即用。

当然,正如 Asaph 指出的那样,Web 框架通常更容易测试。

Most web frameworks abstract away the low level details. For example, Wicket, Tapestry and JavaServer Faces allow you to think in terms of components (e.g., buttons, labels, drop-down list, etc) instead of http protocols. Even action-oriented web frameworks like Spring MVC and Struts bring you a level higher than the underlying technologies used.

As an added bonus, these frameworks come with additional capabilities, such as Ajax, Comet, integration with persistence frameworks, which works out of the box.

Of course, as Asaph has pointed out, web frameworks are usually easier to test.

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