问题描述
将业务逻辑保留在JSP之外的优点是什么,因为JSP的意义主要用于演示?我们仍然看到JSP内部编写的业务逻辑,因此我需要知道通过将业务逻辑从JSP转移到JSP
中获得什么好处.推荐答案
> MVC 您是否可以具有多重视图,清洁和分离的体系结构& 简单
可用性
假设明天您需要在桌面应用程序上运行相同的应用程序.然后,您可以更改视图.
可验证性
您可以单元测试您的服务方法,但是您不能简单地从视图单元测试逻辑.
可维护性
很容易理解服务方法的代码,我们也可以更改/发布服务API并轻松维护
版本能力
如果您使用服务API而不是查看逻辑
,则可以将版本提供给API并维护与问题/更新相关的标准文档另请参见
其他推荐答案
其他推荐答案
我将在此处发布的所有非常好的理由添加一个理由.
客户技术一直在改变.用户不想浏览桌面,浏览器或移动应用程序;他们想一直使用所有这些.因此,如果将业务逻辑嵌入一种类型的用户界面技术中,则可能必须在所有其他用户界面中复制.这对于维护,可重复使用和添加新的业务逻辑不利.
您不想仅仅因为您决定更改UI技术而重写您的应用程序.
也更好.如果业务逻辑归结为浏览器,则用户有可能看到代码并弄清楚您在做什么.
因此,最好将业务逻辑保留在服务器端.
问题描述
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.