【发布时间】:2018-04-14 07:29:00
【问题描述】:
我的控制器中有一个方法如下:
@RequestMapping(value = "/download/attachment/{attachmentId}", method = RequestMethod.GET)
public void download(@PathVariable("attachmentId") String attachmentId, HttpServletRequest request,
HttpServletResponse response) throws IOException {
InputStream file = myCustomObject.getAttachmentById(attachmentId);
response.setContentType("application/octet-stream");
response.flushBuffer();
}
我想使用 Spring 提供的 ControllerLinkBuilder 类生成指向此方法的模板化 HATEOAS 链接。我的链接应该是这样的:
"download" : {
"href" : "https://localhost:8080/download/attachment/{attachmentId}"
}
我在我的 ResourceAssembler 类(扩展 ResourceAssemblerSupport)中使用以下代码:
Link downloadAttachmentLink = linkTo(MyRestController.class, MyRestController.class
.getMethod("download", String.class, HttpServletRequest.class, HttpServletResponse.class),
"{attachmentId}").withRel("download");
我从中得到的链接不是模板化的。它是 URL 编码的。 “{”作为 %7B 发送。我不希望这种情况发生。任何人都可以提出任何建议吗?
【问题讨论】:
标签: java spring spring-hateoas