亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 MvcUriComponentsBuilder.fromMethodName()

從 MvcUriComponentsBuilder.fromMethodName()

素胚勾勒不出你 2021-08-13 15:23:32
我正在使用 MvcUriComponentsBuilder.fromMethodName() 來獲取 URL 列表并將它們返回到前端。以下是示例輸出,其中我以 localhost 的形式獲取域:[ http://localhost:8081/files/1800_tiger.jpg/slideshow , http://localhost:8081/files/1800_trees.jpg/slideshow ]我希望 MvcUriComponentsBuilder 返回我系統的 IP 地址,而不是 localhost。以下是我的代碼實現:     @CrossOrigin     @RestController     public class ContentResource {        @RequestMapping("/getAllFiles")        public ResponseEntity<List<String>> getAllFiles(@RequestParam String panelName) {            List<String> fileNamesList = panelFileListMap.get(panelName);            if (fileNamesList != null) {                List<String> allFiles = fileNamesList.stream()                        .map(fileName -> MvcUriComponentsBuilder                                .fromMethodName(ContentResource.class, "getFile", fileName, panelName).build().toString())                        .collect(Collectors.toList());                return ResponseEntity.ok().body(allFiles);            } else {                throw new RuntimeException("No images are uploaded in category = " + panelName);            }        } @GetMapping("/files/{filename:.+}/{panelName}")    @ResponseBody    public ResponseEntity<Resource> getFile(@PathVariable("filename") String filename,            @PathVariable("panelName") String panelname) {        Resource file = storageService.loadFile(filename, panelname);        return ResponseEntity.ok()                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"")                .body(file);    }        }
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 402 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號