Spring MVC 将RequestMapping添加到控制器

t1rydlwq  于 6个月前  发布在  Spring
关注(0)|答案(3)|浏览(58)

我有个控制器

@Controller
public class ModxProxyController
{
    @RequestMapping("/face/blog")
    public ModelAndView processFace()
    {...}
}

字符串
它只处理URL /face/blog的请求。我需要它来处理(在同一方法中)更多的URL。但到我的应用程序启动的那一刻,我不知道URL。我可以从第三方服务中检索它们一天一次。所以任务是-以编程方式添加要用此方法处理的URL(processFace)。

a2mppw5e

a2mppw5e1#

你可以使用regexp

@RequestMapping("/face/regexp")

字符串
举例说明:

@RequestMapping(value="/{textualPart:[a-z-]+}.{numericPart:[\\d]+}")
public String regularExpression(
  @PathVariable String textualPart,
  @PathVariable String numericPart){

    System.out.println("Textual part: " + textualPart + 
      ", numeric part: " + numericPart);
    return "someResult";
}


http://www.byteslounge.com/tutorials/spring-mvc-requestmapping-example

yqyhoc1h

yqyhoc1h2#

你需要某种形式的共同根,例如:

@RequestMapping("/face/*")

字符串
或者只是一切

@RequestMapping("/")

o4tp2gmn

o4tp2gmn3#

我不确定你是否可以用属性占位符来定义requestmappings。如果可以的话,我会写一个属性求值器来“每天一次”获取这些Map。如果需要的话,你可以在数据库甚至属性文件中实现这种查找。

相关问题