有一个任务将文件路径传递为@PathVariable
在 Spring MVC 到 REST 服务中GET
要求。
我们可以轻松地做到这一点POST
发送 JSON 格式的文件路径字符串。
我们可以怎样做GET
请求和@Controller
像这样?
@RequestMapping(value = "/getFile", method = RequestMethod.GET)
public File getFile(@PathVariable String path) {
// do something
}
Request:
GET /file/getFile/"/Users/user/someSourceFolder/8.jpeg"
Content-Type: application/json
你应该像这样定义你的控制器:
@RequestMapping(value = "/getFile/{path:.+}", method = RequestMethod.GET)
public File getFile(@PathVariable String path) {
// do something
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)