简体   繁体   中英

get url of dynamic html template in spring boot rest controller

我想发送动态呈现的 html 模板并将其 url 作为消息发送到手机,(我有一个 api )我正在使用模型和视图并设置动态数据但是我如何获取它的动态 url 有哪些方法实现这一目标

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM