MVC GET控制器。 PathVariable中的[dot]值

时间:2018-01-04 09:55:46

标签: java spring spring-mvc spring-boot path-variables

这是我的弹簧启动控制器

@GetMapping(value = "/{id}/{fileName}")
@ResponseStatus(HttpStatus.OK)
public Response getDocument(@PathVariable Long id, @PathVariable String filename)

当使用fileName="test.docx"发送请求时,控制器路径变量值为test(缺少.docx)。无论如何都要获取用户传递的参数吗?

我尝试使用

@GetMapping(value = "/{id}/{**fileName:.***}"). 

但是,我在服务器上获得了以下状态码406消息(甚至没有达到控制器代码路径)

  

" exception":" org.springframework.web.HttpMediaTypeNotAcceptableException",     "消息":"找不到可接受的代表",

Spring boot version 1.5.7.RELEASE

1 个答案:

答案 0 :(得分:2)

像这样使用.+

@GetMapping("/{id}/{fileName:.+}") 
@ResponseStatus(HttpStatus.OK) public Response getDocument(@PathVariable Long id, @PathVariable String filename)
相关问题