如何从Spring Boot控制器返回超链接?

问题描述 投票:0回答:1

我想使用Spring Boot在响应主体中为获取请求返回超链接,但是我得到字符串作为响应而不是链接

@GetMapping("/getLinkToFile/{id}")
public URL getLinkToFile(@PathVariable int id) throws Exception {
    URL base = new URL("https://file-examples.com/wp-content/uploads/2017/02/file_example_CSV_5000.csv");
    return base;
}
java spring-boot get request httpresponse
1个回答
0
投票

您可以尝试这个吗,那么您将有想法存档您的问题

@GetMapping(value = "/test")  // just for samples 
  public String getLinkToFile() throws Exception {
    String body =
        "<HTML><body> <a href=\"https://file-examples.com/wp-content/uploads/2017/02/file_example_CSV_5000.csv\">Link clik to go</a></body></HTML>";
    return (body);

  }
© www.soinside.com 2019 - 2024. All rights reserved.