如何组织通用Spring控制器功能?
我知道很多人建议按页面对 Spring 控制器进行分组,即“LoginPageController”和“LandingPageController”等。因此,登录页面的 GET 处理程序和其他请求处理程序都在 LoginPageController 中。
我大部分时间都喜欢这个组织,但最近我添加了更多 AJAX 功能,其中一些功能可以在多个页面上重复使用,而不必绑定到单个页面。我想知道其他人在这种情况下正在做什么。也许为通用控制器制作一个包并尝试在其中对它们进行分类?
任何建议都会很棒!
I know that many people suggest grouping Spring controllers by page, i.e. "LoginPageController" and "LandingPageController," etc. So the GET handler and other request handlers for the login page are in LoginPageController.
I like this organization most of the time, but lately I'm adding more AJAX functionality, some of which can be reused across many pages and isn't necessarily tied to a single page. I'm wondering what other people are doing in this situation. Maybe make a package for general purpose controllers and try to categorize them in there?
Any advice would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我更喜欢按功能分组。根据您的示例,我将有一个 ProjectController 来处理与项目相关的页面以及获取/更新项目数据的 Ajax 调用。
I prefer to group by function. Given your example, I would have a ProjectController that handles both the pages related to Projects as well as the Ajax calls that get/update project data.