【问题标题】:How to return a hyperlink from spring boot controller?如何从 Spring Boot 控制器返回超链接?
【发布时间】:2020-01-26 13:49:33
【问题描述】:

我想在响应正文中为使用 Spring Boot 的 get 请求返回一个超链接,但我得到的是字符串作为响应而不是链接

@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】:

你能试试这个吗,然后你就会想办法把你的问题归档

@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);

  }

【讨论】:

    猜你喜欢
    • 2018-07-14
    • 2019-12-05
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 2021-06-15
    • 2016-12-06
    相关资源
    最近更新 更多