简体   繁体   English

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

[英]Spring Request Mapping URL's to One Controller

I have asked a recent question regarding a similar urls mapping to the same controller. 我问了一个最近的问题,关于类似的URL映射到同一控制器。 In this case I had to give it 3 or 4 urls which is fine. 在这种情况下,我必须给它3或4个网址,这很好。

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. 我的问题现在是,实际上有100-150个网址会通过一个控制器。 These URL's are to be contained in a database. 这些URL将包含在数据库中。 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. 我正在寻找一种优雅的方式来在“请求映射”中保持此状态,而不是放置100个不同的URL(可能会更改),尤其是因为我正在工作的客户端不想对后端进行任何更改。 Is there an elegant way to do this? 有没有一种优雅的方法可以做到这一点? Thanks. 谢谢。

I'd probably start by looking at ways to provide a SimpleUrlHandlerMapping subclass that grabbed its list of values from the DB. 我可能首先要研究提供SimpleUrlHandlerMapping子类的方法,该子类从数据库中获取其值列表。 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). 它非常简单明了,使您不必参与任何扫描,并使配置相当局部化为一个XML块(加上DB的东西)。

(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.) (我认为您只需要实现HandlerMapping但是从SimpleUrlHandlerMapping开始可能会更快-对我来说这将是明天的测试技巧。)

You don't say whether or not these URLs need to change at runtime; 您无需说这些URL在运行时是否需要更改; 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. 如果他们这样做了,那么您将需要具有更深层次的了解来更新实际映射-不确定如何做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM