I want to send dynamic rendered html template and send its url as a message to the phone,( I have an api for that ) I am using Model and View and setting the dynamic data but how do I get its dynamic urls what are the approaches to achieve that
Asked
Active
Viewed 996 times
0
-
Does this answer your question? [What's the best way to get the current URL in Spring MVC?](https://stackoverflow.com/questions/1490821/whats-the-best-way-to-get-the-current-url-in-spring-mvc) – y434y Jun 02 '22 at 08:28
1 Answers
1
You can use Thymeleaf to render your Html and save it temporary with a unique name.
How to do it exactly is described here
Now you need a @Controller with a @Getmapping.
@GetMapping("/htmls/{unique}")
@ResponseBody
public String ResponsePerson(
@PathVariable("unique") String unique) {
return htmlString
}
You can get the Html String in diff. Ways. One example way is:
File htmlFile = new File("src/main/ress/htmls/"+unique+"html");
String htmlString = FileUtils.readFileToString(htmlFile,
StandardCharsets.UTF_8);
Your link should look like: http//:yor.ip.adress:8080/htmls/unique
Edit: Sorry forgot to add the @ResponseBody Annotation. You need that to bind the returned String to the Web Response Body.

Sigurd Mazanti
- 2,098
- 1
- 8
- 24

Christoph Kronberger
- 136
- 9