为什么业务逻辑应该从JSP中移出?[英] why business logic should be moved out of JSP?

本文是小编为大家收集整理的关于为什么业务逻辑应该从JSP中移出?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

将业务逻辑保留在JSP之外的优点是什么,因为JSP的意义主要用于演示?我们仍然看到JSP内部编写的业务逻辑,因此我需要知道通过将业务逻辑从JSP转移到JSP

中获得什么好处.

推荐答案

> MVC 您是否可以具有多重视图,清洁和分离的体系结构& 简单


可用性

假设明天您需要在桌面应用程序上运行相同的应用程序.然后,您可以更改视图.


验证

您可以单元测试您的服务方法,但是您不能简单地从视图单元测试逻辑.


可维护性

很容易理解服务方法的代码,我们也可以更改/发布服务API并轻松维护


版本能力

如果您使用服务API而不是查看逻辑

,则可以将版本提供给API并维护与问题/更新相关的标准文档

另请参见

其他推荐答案

这是设置关注原则的典型应用.

通过分开关注点,即通过创建单独的逻辑单元(主要是类),您可以减少更改任何特定单元的原因.
SOC的另一个好处是减少平均大小和这些单元的复杂性.反过来,这使您的软件更易于理解和更改.

此外,拥有较小的逻辑单元使它们更容易单位测试,更易于在集成测试中模拟,并且在更改实现后更易于修复测试.

其他推荐答案

我将在此处发布的所有非常好的理由添加一个理由.

客户技术一直在改变.用户不想浏览桌面,浏览器或移动应用程序;他们想一直使用所有这些.因此,如果将业务逻辑嵌入一种类型的用户界面技术中,则可能必须在所有其他用户界面中复制.这对于维护,可重复使用和添加新的业务逻辑不利.

您不想仅仅因为您决定更改UI技术而重写您的应用程序.

也更好.如果业务逻辑归结为浏览器,则用户有可能看到代码并弄清楚您在做什么.

因此,最好将业务逻辑保留在服务器端.

本文地址:https://www.itbaoku.cn/post/627482.html

问题描述

What are the advantages of keeping the business logic outside JSP, since JSP's are meant mainly for presentation? We still see business logic written inside the JSP, so I needed to know what benefit we get by moving business logic out of JSP.

推荐答案

The main benefit of MVC is you can have multiple view and clean and separated architecture & Simplicity


Re usability

Suppose tomorrow you need same app running on a desktop app. then you can just change the view.


Testability

You can unit test your service methods, but you can't simply unit test logic from view.


Maintainability

It is easy to understand the code from Service methods, also we can change it /release service api and maintain it easily


Version ability

You can give version to your API and maintain standard docs related to issues/updates if you use service API instead view for logic


See Also

其他推荐答案

It is a typical application of the Separation of Concerns design principle.

By separating concerns, i.e. by creating separate logical units (mainly classes) for each of them you reduce the number of reasons to change any particular unit.

Another benefit of SoC is reducing the average size and complexity of these units. This in turn makes your software easier to understand and to change.

Furthermore having small logical units makes them much easier to unit test, easier to mock in integration tests and easier to fix the tests after changes in the implementation.

其他推荐答案

I'll add one more reason to all the very good ones that are posted here.

Client technology is changing all the time. Users don't want to come through a desktop, browser, or mobile app; they want to use all of them, all the time. So if you embed business logic in one type of user interface technology, you'll probably have to duplicate it in all the others. That's bad for maintenance, reusability, and adding new business logic.

You don't want to have to re-write your app just because you decide to change UI technology.

It's also better for security. If business logic goes down to the browser, there's a chance that users could see the code and figure out what you're doing.

So you're better off keeping business logic on the server side.