【发布时间】:2018-07-31 10:43:29
【问题描述】:
我有一个像下面这样的处理方法,它需要 fileName
@GetMapping(value = ["/test/{fileName:.+}"], produces = [(MediaType.APPLICATION_JSON_VALUE)])
fun getFile(@PathVariable fileName: String): ResponseEntity<Map<String, String>> {
return ResponseEntity.ok(hashMapOf(Pair("fileName", fileName)))
}
我遇到了一些奇怪的行为,即
- 调用
/test/item-1.exx结果到{"fileName": "item-1.exx"} - 调用
/test/item-1.855结果到{"fileName": "item-1.855"} - 调用
/test/item-1.pn8结果到{"fileName": "item-1.pn8"}
但如果我尝试使用有效扩展名调用该方法,我会得到 406 Not Acceptable。
- 调用
/test/item-1.png结果到406 Not Acceptable - 调用
/test/item-1.jpg结果到406 Not Acceptable - 调用
/test/item-1.exe结果到406 Not Acceptable
我得到以下异常
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
如何解决这个问题?我希望能够使用有效的扩展名调用该方法。
【问题讨论】:
-
使用 Spring Boot 1.5.9.RELEASE
标签: java spring spring-mvc spring-boot kotlin