Spring 请求将 URL 映射到一个控制器

发布于 2024-12-10 06:11:45 字数 433 浏览 0 评论 0原文

我最近问了一个关于映射到同一控制器的类似网址的问题。 在这种情况下,我必须给它 3 或 4 个 url,这很好。

Spring 请求映射错误

该示例包含以下内容。

@RequestMapping({"/protect", "/protekt", "/proteckt", "/protext"})

我现在的问题是有 100-150 个 url 基本上会通过一个控制器。这些 URL 将包含在数据库中。我正在寻找一种优雅的方法来在请求映射中维护它,而不是放置 100 个不同的 URL(可能会更改),特别是因为我正在工作的客户不想对后端进行任何更改。有没有一种优雅的方法来做到这一点?谢谢。

I have asked a recent question regarding a similar urls mapping to the same controller.
In this case I had to give it 3 or 4 urls which is fine.

Spring Request Mapping Mis

The example contained the following.

@RequestMapping({"/protect", "/protekt", "/proteckt", "/protext"})

My issue now is there are 100-150 urls that weill essentially go through ONE controller. These URL's are to be contained in a database. I am looking for an elegant way to maintain this in the Request Mapping rather than putting 100 different URLS(that may change) particularly because the client I am working for doesn't want to make any changes to the back end. Is there an elegant way to do this? Thanks.

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

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

发布评论

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

评论(1

韵柒 2024-12-17 06:11:45

我可能会首先考虑提供 SimpleUrlHandlerMapping 子类,从数据库中获取其值列表。它非常简单,使您无需进行任何扫描,并使配置保持本地化到一小块 XML(加上数据库内容)。

(我认为您只需要实现HandlerMapping 但从 SimpleUrlHandlerMapping 开始可能会更快 - 这将是明天的测试黑客我。)

你没有说这些 URL 是否需要在运行时更改;如果他们这样做,那么你需要能够在更深的层次上连接来更新实际的映射——我不知道如何做到这一点。

I'd probably start by looking at ways to provide a SimpleUrlHandlerMapping subclass that grabbed its list of values from the DB. It's pretty straight-forward, keeps you from having to hook into any scanning, and keeps the configuration pretty localized to one chunk of XML (plus DB stuff).

(I think you only need to implement a HandlerMapping but it might be quicker to start from a SimpleUrlHandlerMapping--that'll be tomorrow's test hack for me.)

You don't say whether or not these URLs need to change at runtime; if they do then you'd need the ability to hook in at a deeper level to update the actual mappings--not sure how to do that off the top of my head.

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