k.prerna
k.prerna

Reputation: 31

How to return a hyperlink from spring boot controller?

I want to return a hyperlink in the response body for a get request using Spring Boot, but i am getting string as a response and not link

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

Upvotes: 2

Views: 3762

Answers (1)

Dulaj Kulathunga
Dulaj Kulathunga

Reputation: 1250

Can you try this one please , then you will get idea to do archive your problem

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

  }

Upvotes: 3

Related Questions