spring @RequestMapping像url这样的变量值

时间:2016-01-18 17:41:49

标签: spring-mvc

我有@RequestMapping(value = "/image/{path}",method = RequestMethod.GET) 在我的控制器中

我需要以某种不同的方式使用{path}变量,例如:path可能是" image.png"在其他时间可能是" /resources/images/image.png" ..

我的问题:可以像路径一样处理变量 - > "/resources/images/image.png"

1 个答案:

答案 0 :(得分:0)

/.会将变量分解为多个部分。使用路径变量而无需任何其他配置,您必须将文件名拆分为两个单独的路径变量,如

@RequestMapping(value = "/image/{filename}/{extension}", method = RequestMethod.GET)
public [ReturnType] myMethod(
   @PathVariable("filename") String file,
   @PathVariable("extension") String ext) { ... }