建议使用哪种方式将操作类映射到请求?

发布于 2024-10-20 08:34:11 字数 504 浏览 1 评论 0原文

在 struts 2 中,动作到类的映射可以通过两种方式完成:(请原谅错误的语法)

action = "action1" class = "class1" results = "results1"
action = "action2" class = "class2" results = "results2"

等等,每个 action = 1 , 2 ....n 即每个 1 个动作类请求

或者:

action = "action1" class = "class1" results = "results1" method = "method1"
action = "action2" class = "class1" results = "results1" method = "method2"

等等。即所有请求只有 1 个操作类。但每个动作都有一个单独的方法。

有什么时候使用的最佳实践吗?

In struts 2, the action to class mapping can be done in 2 ways:(Please pardon the wrong syntax)

action = "action1" class = "class1" results = "results1"
action = "action2" class = "class2" results = "results2"

and so on for each action = 1 , 2 ....n i.e. 1 action class per request

Or:

action = "action1" class = "class1" results = "results1" method = "method1"
action = "action2" class = "class1" results = "results1" method = "method2"

and so on. i.e only 1 action class for all requests. But each action has a separate method.

Is there any best practice which to use when?

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

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

发布评论

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

评论(1

南渊 2024-10-27 08:34:11

将其视为一般的 Java 问题。我应该创建一个新类来解决这个问题还是应该创建一个新方法来解决这个问题?也就是说,这是一个新事物还是更好地表达为现有事物的行为。

如果您有一个将显示员工的页面,那么它值得一个操作类。如果您有另一个显示公司的页面,则值得另一个操作类。我喜欢将 CRUD 和某些 Ajax 功能放入同一个类中,因为我认为我较少这样做。

然而,让一个动作类加载有将不相关的想法混杂在一起的方法是没有意义的,无论如何这都不是 Java 的思维方式。

实际上,对一个班级的一项行动是个人喜好的事情,但我认为无论你做什么,你都应该保持一致。不需要太多 crud 或 ajax 的项目可能很少使用方法作为操作,因此最好始终避免使用它们。

Think of it as you would a general Java problem. Should I create a new class to address this issue or should I create a new method to address this issue? That is, is this a new thing or better expressed as a behavior of an existing thing.

If you have a page which will display employees, then that deserves an action class. If you have another page that displays companies, that deserves another action class. I like to put CRUD and certain Ajax features into the same class because I think I move around less that way.

It wouldn't however make sense to have one action class loaded with methods mashing together unrelated ideas, well it wouldn't be Java thinking anyways.

Really one action to one class is a personal preference thing but I think you should be consistent what ever you do. Projects that don't require much crud or ajax perhaps would use methods as actions so rarely that perhaps it would be better to just consistently avoid them.

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